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
Pass username and password to another page
Moderator: General Moderators
Re: Pass username and password to another page
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.
-
sunilbhatia79
- Forum Newbie
- Posts: 24
- Joined: Sun Nov 11, 2007 9:37 pm
- Location: Mumbai, India
Re: Pass username and password to another page
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
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
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
account.php
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>
Code: Select all
<?php
session_start(); //start the session again
echo "Hello " . $_SESSION['username'] . "!<br/>
Your password is: " . $_SESSION['password'] . "<br/>";
?>