Page 1 of 1
Pass username and password to another page
Posted: Wed Feb 27, 2008 8:24 am
by bryanas
How can I pass the values of a username and password from one form to another. I tried the following on the second page but must be missing something:
<form method=post action="catelog.cgi">
<input type="Hidden" name="USERNAME" value="<?=HTTP_POST_VARS['USERNAME']?>">
<input type="Hidden" name="PASSWORD value="<?=HTTP_POST_VARS['PASSWORD']?>">
<input type=submit name=submit value="Submit">
</form>
Thanks,
Bryan
Re: Pass username and password to another page
Posted: Wed Feb 27, 2008 8:37 am
by Zoxive
Passwords are sensitive data you do NOT want to be outputting to the browser.
Use
Sessions instead.
Re: Pass username and password to another page
Posted: Wed Feb 27, 2008 9:46 am
by bryanas
I have never used sessions before. How would I do this passing a username and password to the next page? I saw the link but it looks complex.
Re: Pass username and password to another page
Posted: Wed Feb 27, 2008 9:50 am
by sunilbhatia79
In the below code you missed the $ symbol
value="<?=HTTP_POST_VARS['USERNAME']?>">
value="<?=HTTP_POST_VARS['PASSWORD']?>">
Corrected
value="<?=$HTTP_POST_VARS['USERNAME']?>">
value="<?=$HTTP_POST_VARS['PASSWORD']?>">
Sunil
PHP5 Tutorials
Re: Pass username and password to another page
Posted: Wed Feb 27, 2008 9:57 am
by Jade
You'll need to read the page on sessions. Essentially on the login page you need to start a session. When the user enters their login/password into the form you need to post that data and store it in your sessions. Then on another page you can start the session and pull the username and password out. It might look something like this:
Login.php
Code: Select all
<?php
session_start();
if ($_POST['submit'])
{
//check to see if that's a valid login
//if its a valid login save the information in a session
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
//close the session and write data
session_write_close();
//redirect the user to some other page
header("Location: account.php");
exit;
}
?>
<form action="#" method="post">
Login<br/><br/>
Username: <input type="text" name="username"/><br/>
Password: <input type="password" name="password" /><br/>
<input type="submit" name="submit" value="Login" /><br/>
</form>
account.php
Code: Select all
<?php
session_start(); //start the session again
echo "Hello " . $_SESSION['username'] . "!<br/>
Your password is: " . $_SESSION['password'] . "<br/>";
?>