i wanna pass these variables to another php file

please can someone help me out?

while ($i < 10)

$Variable1 = $1;
$Variable2 = “Hello”;

        /* i wanna pass these variables to another php file 
 say "http://localhost/receiver.php

Once the variables are recieved in the receiver.php, its gonna pass them to an sms gateway
        header('Location: http://www.address.com/file.php?var1 = ' . $Variable1 . '&var2=' . $Variable2 '); */



the problem i am facing is that, after the first set of variables is gone, the header function overrides the existing
hence the rest of the loop does not get to execute

is there a way out with php alone?

thank you.

I could be wrong here, (I am fairly new to this myself), but if you want to pass the variables from one php file to another (presuming this is web PHP) you will need to use SESSION or GET or POST like when you use a form.

So it becomes a global variable of sorts.

Might give you somewhere to look for further informati

ok thanx ablueman please where can i get further info?

Without meaning to be facetious but google is a good place to start :slight_smile:


You need to decide how you want to pass the information. ( I would also keep an eye here in case someone has a better answer ).

a session is best for where you will need that variable across most if not all of the site.
get and post are slightly less access all areas, but read up on the differences between them.

Security is something you should consider. one of these methods just passes the information in the web address itself. Great if you want people to be able to shortcut to a product or something, not so good if your passing a username and password.

Perhaps here: http://mrarrowhead.com/index.php?page=php_passing_variables.php

Good luck :slight_smile:

Without meaning to be facetious but google is a good place to start :slight_smile: :-[ :slight_smile: i know right! i just wanted a quick fix - but thanks- i think am beginning to get it - i would try it out and i will also check out the link you provided also. would let you know my progress so far.

I am not sure what your main goal is for the while() loop but you are correct with your url in passing variables to another page
header(‘location: http://www.example.com?var1=1&var2=Hello’);
will allow you to retrieve the variabes var1 and var2 from another page using…
$varOne = $_GET[‘var1’];
$varTwo = $_GET[‘var2’];

echo $varOne." ".$varTwo;

if you were to execute that it should show -
1 Hello

Does this help at all?

thank you sir, but the problem is when i use the header() the page navigates to the new one and my loop ends prematurely -

hope i made any sense :-\

You can’t stop the header() from doing that. That is the point of it. What exactly are you trying to accomplish with the while() loop?

thank you sir, once again - my problem is solved.

this did the trick

$trans = file_get_contents(‘http://www.domain.com/somefile?var=xxxx&var2=xxxxx’);

I just want to mention that in order to use file_get_contents() with a URL you have to set your php.ini to allow_url_fopen = On which is a security risk.

You can most likely accomplish the same results using cURL without enabling allow_url_fopen

I’ll be happy to post an example if you need one.

ok m@tt thanks - i will need all the help i can get

An example would be great!
thank you m@tt.

Sponsor our Newsletter | Privacy Policy | Terms of Service