Array on external scripts usage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jgt
Forum Newbie
Posts: 12
Joined: Thu Nov 02, 2006 6:07 am

Array on external scripts usage

Post by jgt »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I would like to know if a PHP generated array could be used as a POST/GET variable on another script call. Let me explain with an example.

Code: Select all

<?php
  $data = Array();

// some code that fills in the n-dimension array.

  print("<IMG SRC='AnotherScript.php?Data=".$data."'>"); // I would like to use $data as a GET parameter
?>
AnotherScript.php

Code: Select all

<?php
  $anotherData = $_GET["Data"];
// Some code that uses $anotherData array contents to generate an image.

?>
I would like to use the $data array contents generated on first script as a GET variable in the image generation performed by AnotherScript.php


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Not the way you have it.

You'll receive the string "Array" with your current code. Typically, if you want to pass array based information to another script via URL you have to write it such that it generates an array on the other side.

foo.php?bar[hi]=ten&bar[10]=super

for example.
jgt
Forum Newbie
Posts: 12
Joined: Thu Nov 02, 2006 6:07 am

Post by jgt »

Thanks for your answer.
I founded this solution but I suppose that you'll agree with me that when this array is really big (I'm managing near 100 matrix elements) it could be unmanageable on both scripts.

Is this the only way to pass arrays between scripts using URL?

I thought that, as a multi choince combo box form control generates an array that could be passed to the PHP script, this other way to work could be possible.

:cry:
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

possible solution would be to user sessions and create a $_SESSION['yourArray'] = $yourArray variable which can be passed between scripts; using:

Code: Select all

if(isset($_SESSION['yourArray'])){
$yourArrayInAnotherScript = $_SESSION['youArray'];
}
in your other script that wants to use the array.

like you said size could be the problem here with a few elements i dont think this would be much of a issue but with hundreds of elements it could have adverse effects on your server.
Post Reply