[FIN]Is it possible to send a variable without using a form?

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
Bbob
Forum Commoner
Posts: 57
Joined: Sat Aug 07, 2010 4:46 am

[FIN]Is it possible to send a variable without using a form?

Post by Bbob »

Hi

Is it possible to send a variable to another page without using a form?

For example....

send.php

Code: Select all

<?php
  $me =1;
  echo $me;
?>
receive.php

Code: Select all

$hi = $me + 3;
echo $hi;
How do I send $me (that was echoed) from send.php to receive.php?
Last edited by Bbob on Sun Oct 17, 2010 6:48 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Is it possible to send a variable without using a form?

Post by requinix »

Yes, it's possible. But what you do depends on why you need it.
jaceinla
Forum Commoner
Posts: 25
Joined: Thu Oct 14, 2010 12:57 pm

Re: Is it possible to send a variable without using a form?

Post 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

Code: Select all

$me = $_GET['me'];  //7
echo $me;
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
Bbob
Forum Commoner
Posts: 57
Joined: Sat Aug 07, 2010 4:46 am

Re: Is it possible to send a variable without using a form?

Post 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?
jaceinla
Forum Commoner
Posts: 25
Joined: Thu Oct 14, 2010 12:57 pm

Re: Is it possible to send a variable without using a form?

Post 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.
Bbob
Forum Commoner
Posts: 57
Joined: Sat Aug 07, 2010 4:46 am

Re: Is it possible to send a variable without using a form?

Post by Bbob »

Sounds a bit complicated xD

I guess Ill stick with $_SESSION :D


Thanks for the reply.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: Is it possible to send a variable without using a form?

Post 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.
Post Reply