469,330 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

How does one pass array variables between URLs?

I would like to pass array variables between URLs but I don't know
how. I know its possible with sessions, but sessions can become
useless if cookies are disabled. I have unsuccessfully tried using
post and get methods.

Thank you
John
Jul 17 '05 #1
5 31307
jk*****@yahoo.com (John) wrote in message
news:<f6**************************@posting.google. com>...

I would like to pass array variables between URLs but
I don't know how.


serialize() your array before passing it out and unserialize()
it on the receiving end:

http://php.net/serialize
http://php.net/unserialize

Cheers,
NC
Jul 17 '05 #2
On 20 Dec 2003 10:54:38 -0800, jk*****@yahoo.com (John) wrote:
I would like to pass array variables between URLs but I don't know
how. I know its possible with sessions, but sessions can become
useless if cookies are disabled. I have unsuccessfully tried using
post and get methods.


Use [] on the end of the variable name.

whatever.php?x[]=1&x[]=2&x[]=3

... will produce a three-element array in $_GET['x'].

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #3
Regarding this well-known quote, often attributed to John's famous "20 Dec
2003 10:54:38 -0800" speech:
I would like to pass array variables between URLs but I don't know
how. I know its possible with sessions, but sessions can become
useless if cookies are disabled. I have unsuccessfully tried using
post and get methods.

Thank you
John


You can still use sessions, and enable link-rewriting and hidden form
elements to pass the session ID, along with the usual cookies. This is less
secure, and could be more easily hijacked, but if the information you're
sessioning doesn't need to be secret, it's probably no big deal.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #4
Andy Hassall <an**@andyh.co.uk> wrote in message news:<bf********************************@4ax.com>. ..
On 20 Dec 2003 10:54:38 -0800, jk*****@yahoo.com (John) wrote:
I would like to pass array variables between URLs but I don't know
how. I know its possible with sessions, but sessions can become
useless if cookies are disabled. I have unsuccessfully tried using
post and get methods.


Use [] on the end of the variable name.

whatever.php?x[]=1&x[]=2&x[]=3

... will produce a three-element array in $_GET['x'].


You can even pass multi-dimensional associative array in similar way
by using [] syntax.

for example:

whatever.php?myArr[a][x]=1&x[a][y]=2&x[b][x]=3

... will produce

$myArr = Array
(
[a] => Array
(
[x] => 1
[y] => 2
)

[b] => Array
(
[x] => 3
)

)

for secure array passing use *SESSION*

-- Rahul
Jul 17 '05 #5
FLEB <so*********@mmers.and.evil.ones.will.bow-down-to.us> wrote in message news:<1l*****************************@40tude.net>. ..
Regarding this well-known quote, often attributed to John's famous "20 Dec
2003 10:54:38 -0800" speech:
I would like to pass array variables between URLs but I don't know
how. I know its possible with sessions, but sessions can become
useless if cookies are disabled. I have unsuccessfully tried using
post and get methods.

Thank you
John


Here is a little trick I use (I know, some people may not like it) but
scripting with duct tape can be fun! Note: this does not work across
site wide, unless you work it into all your links and pages, it is
best for passing large data between few pages.

ok fist thing you need to do is create an uniq ID for the user, and
pass it along with the url. I tend to use:

$sID = md5("some id text" . $_SERVER['SCRIPT_NAME'] . time());

then on our links use:

a href=/some_page.php?sid=<?php print $sID; ?>
ok, now on your page that has the data, write it to a file (use a
cache dir [make sure it is writeable])

$sesFile = "_cache/$sID";
// open the file, write php head
$fp = fopen($sesFile,"w");
fwrite($fp,"<?php\n");
$wInfo = var_export($YOUR_ARRAY_NAME,TRUE);
// write the var name and data
fwrite($fp,"\$"."YOUR_ARRAY_NAME = "); // do not put $ on array name!
fwrite($fp,$wInfo.";\n");
// write php end, and close file
fwrite($fp,"?>\n");
fclose($fp);
This creates a file that you can load right into a php script to have
your array back

so on the following page that you want your data array available on
use this at the top

$sID = $_GET['sid'];
include("_cache/$sID");

thats it, your array is now loaded and ready to use.

ok, the bad side of this, writing files, and accumulating them, you
need to find a way to delete these files that is best for you, you
could delete the array after you load it, but there is a chance it
wont delete, becouse they never went to the following page.

I have a _cache dir on my server, and delete files over 30 days old,
this could work for you, but then ties you into the server, and sites
are not as portable.

hope this helps,

Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Frostillicus | last post: by
14 posts views Thread by billy.becker | last post: by
3 posts views Thread by csx | last post: by
13 posts views Thread by Jason Huang | last post: by
10 posts views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.