473,372 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 31518
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lawrence | last post by:
Maybe its late and I'm tired but I don't understand what I'm seeing on the screen. I have this block of code: $choiceMade = $_GET; if ($simpleMode == "y" && $choiceMade == "") {...
5
by: Frostillicus | last post by:
I'm trying to use array_multisort to sort by one of the dimensions of an array stored in $GLOBALS like this: array_multisort($GLOBALS, SORT_STRING, SORT_DESC); Each "row" in $GLOBALS contains...
14
by: billy.becker | last post by:
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST superglobal array? I haven't been able to find any...
4
by: Stephen Williams | last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere between 5 and 20. What I want to do is write a function that returns the captions of every ticked tick box in an array...
30
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then...
3
by: csx | last post by:
Hi all, Ive got a problem with recursion in Javascript. For this tree: http://www.pcm.uklinux.net/structure.jpg If you input node 3 (i.e. C) which is represented as 'values' in the array, it...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
10
by: tshad | last post by:
I want to access multiple arguments based on name passed. For example I have the following asp:textboxes: BillingAddress1 BillingAddress2 BillingCity ShippingAddress1 ShippingAddress2...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.