Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting Variables

Status
Not open for further replies.

Quijian

ISP
Jul 9, 2004
32
US
Is it possible to move variables from one page to another, without using MySQL? Sorry, I am a noob. All help appreciated.
 
Hi,

If you wish to move variables from one page to another, there are several ways:

Code:
<a href="page2.php?variable1=yes&amp;variable2=no" title="yes and no">yes and no</a>

This will use the querystring.. (the least secure option)

Or, you can do:
Code:
<form action="page2.php" method="post">
  <input type="text" name="variable1" value="yes" />
  <input type="text" name="variable2" value="no" />
  <input type="submit" name="submit" action="submit" />
</form>

Also, you can do:

Code:
session_start();
if (isset($variable1)) {
  $_SESSION['variable1'] = $variable1;
}
if (isset($variable2)) {
  $_SESSION['variable2'] = $variable1;
}

If you want a login script, you use the session.
If you want some basic things, it's often easy to use querystring.
If you want the user to log in, or register, or whatever, you use the form, maybe combined with session.

Note for sessions:
On EACH page that you wish to use the session variables that you define, you have to start on the top-most of the page:

session_start();

You can not have any whitespace or anything parsed before that! Or you will get some error "headers already sent" or something like that.

ps. As always, you need to remove unwanted things from your variables, as they might be abused in one way or another.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top