0

I would like to know how can I access or read the array from another page. I am working on a PHP page which contains the array, and I want to display the content of that array on another PHP page.

For example, I used the following method in a PHP file and I want to get the content of the array in another PHP file. what is the method that is going to receive the array's content in the second page.

<?php
$r = new HttpRequest('http://localhost/sameh.php', HttpRequest::METH_POST);
$r->addPostFields(array("n" => 'heba')) ;
$r->send();
?>

This code is in the first page but I don't know what to write to receive it on the second one.

Maybe my question was not that clear and sorry about that ,, I want to find a way to access the array that is defined inside the HttpRequest() class on another page. So that the array "n" that include value "heba" will be displayed on another.php page. this is what make me thinking that the problem is on how to access the content of the array on the second page.

I tried the session and It sends the array to another page ,, but when I tested with the httpRequest() method it doesn't send the content of the array "heba" to the second page.

Thanks for your help.

Heba Dawoud
  • 1
  • 1
  • 2
  • 1
    If the array is a static one, put it in a file, include that file in both. If it's dynamic (different content every time) you should study session handling on PHP. – AbiusX Mar 15 '11 at 21:48

5 Answers5

3

Sounds like this is a job for Sessions.

You can read the complete session guide here

In the script that has the array you can do something like:

session_start();
$_SESSION['array'] = $array;

In the next script you access it similarly:

session_start();
print_r($_SESSION['array']);
vicTROLLA
  • 1,554
  • 12
  • 15
0

Note that to work with serialized arrays, you need to use POST as the form's transmission method, as GET has a size limit somewhere around 1024 characters.

I'd use SESSIONs wherever possible.

V A S
  • 3,338
  • 4
  • 33
  • 39
0

Include that file in your php file where you want to use that array. This should solve your issue PHP - How to send an array to another page?

Community
  • 1
  • 1
yogsma
  • 10,142
  • 31
  • 97
  • 154
0

I'm not sure what the HttpRequest class is, but at a guess, it's POSTing variables to the sameh.php file. You should be able to access the variable on the next page by doing this:

echo $_POST['n'];

Which should print "heba".

Sam Starling
  • 5,298
  • 3
  • 35
  • 52
0

You can use serialize() and unserialize() on your array to represent it as a string and pass it via POST.

Thusitha Sumanadasa
  • 1,669
  • 2
  • 22
  • 30
user470714
  • 2,858
  • 1
  • 28
  • 34