473,657 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 31538
jk*****@yahoo.c om (John) wrote in message
news:<f6******* *************** ****@posting.go ogle.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.c om (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.ev il.ones.will.bo w-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.c om (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?my Arr[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*********@mm ers.and.evil.on es.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?s id=<?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,"<?p hp\n");
$wInfo = var_export($YOU R_ARRAY_NAME,TR UE);
// write the var name and data
fwrite($fp,"\$" ."YOUR_ARRAY_NA ME = "); // do not put $ on array name!
fwrite($fp,$wIn fo.";\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
2333
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 == "") { startPage(); printEasyControlPanelOptions(); endPage();
5
2833
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 a value for 'href', 'desc', and 'info' but when I try to pass one of these "columns" to array_multisort() it whinges about it not being an array or a sort value :-( Can PHP not understand arrays stored in $GLOBALS or something?
14
4327
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 info on this.... I have a script that does what I want in PERL, but I need to do it in PHP. I think the PERL does something magic when it does this:
4
2955
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 as a string. I want to be able to pass to the function the array name, and the lower and upper limits of the array. But I have no idea how to pass the control name (array name).
30
3436
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 I've also heard there are lots of weird ways to do some things kinda like Perl which is bad for me. Any other ideas?
3
4692
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 should return all the 'leaf' nodes. In this case 4! Node 4 (i.e. D) is not included in the count.
13
5035
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
1556
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 ShippingCity
11
3342
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 ways of passing an array. In the following code, fun1(int a1) - same as fun1(int* a1) - where both are of the type passed by reference. Inside this function, another pointer a1 is created whose address &a1 is different from that of the passed...
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.