Page 1 of 1

Array on external scripts usage

Posted: Thu Nov 02, 2006 6:44 am
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]

Posted: Thu Nov 02, 2006 7:19 am
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.

Posted: Thu Nov 02, 2006 7:43 am
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:

Posted: Thu Nov 02, 2006 8:12 am
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.