Page 1 of 1
[FIN]Is it possible to send a variable without using a form?
Posted: Fri Oct 15, 2010 10:40 pm
by Bbob
Hi
Is it possible to send a variable to another page without using a form?
For example....
send.php
receive.php
How do I send $me (that was echoed) from send.php to receive.php?
Re: Is it possible to send a variable without using a form?
Posted: Fri Oct 15, 2010 11:36 pm
by requinix
Yes, it's possible. But what you do depends on why you need it.
Re: Is it possible to send a variable without using a form?
Posted: Sat Oct 16, 2010 12:26 am
by jaceinla
You can send it via url
http://send.php?me=5&you=3
SEND.PHP
Code: Select all
$me = 3 + 4;
<a href="/receive.php?me=<?php echo $me ?>">Link</a>
RECEIVE
One way to send it, URL is not a form (as in input) in my book, but if you think it is, you could always use $_SESSION as another way
Re: Is it possible to send a variable without using a form?
Posted: Sat Oct 16, 2010 1:44 am
by Bbob
tasairis wrote:Yes, it's possible. But what you do depends on why you need it.
I have a page where I retrieve & display the quantity of an item from the DB. Then I have another page where I use the quantity to compute the total.
@jaceinla
Thanks for the answer. Are there other options besides using a URL and $_SESSION?
Re: Is it possible to send a variable without using a form?
Posted: Sat Oct 16, 2010 2:28 am
by jaceinla
It would be OO, but I believe if send and receive can both extend the same class which holds the DB var value within it, they can then both retrieve it. Using a get and set method.
Re: Is it possible to send a variable without using a form?
Posted: Sun Oct 17, 2010 6:47 am
by Bbob
Sounds a bit complicated xD
I guess Ill stick with $_SESSION
Thanks for the reply.
Re: Is it possible to send a variable without using a form?
Posted: Sun Oct 17, 2010 10:02 am
by Sephern
jaceinla wrote:It would be OO, but I believe if send and receive can both extend the same class which holds the DB var value within it, they can then both retrieve it. Using a get and set method.
An object only exists in one pageload. It'd be the same as any other PHP variable.
You have a couple of options I suppose.
Firstly, you could use Session variables as others have indicated.
The second is that you could send it via $_GET in the URL, and pick it up on the next PHP page.
Thirdly, you could have one page which provides the front-end to the user, which uses AJAX to load the pages one after another, meaning you could send the input via POST or GET to the PHP pages through javascript.
The final technique would be to cache the variable, using either APC or memcache.
Sessions are probably the best method for you.