Pass username and password to another page

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
bryanas
Forum Newbie
Posts: 2
Joined: Wed Feb 27, 2008 8:21 am

Pass username and password to another page

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Pass username and password to another page

Post by Zoxive »

Passwords are sensitive data you do NOT want to be outputting to the browser.

Use Sessions instead.
bryanas
Forum Newbie
Posts: 2
Joined: Wed Feb 27, 2008 8:21 am

Re: Pass username and password to another page

Post 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.
sunilbhatia79
Forum Newbie
Posts: 24
Joined: Sun Nov 11, 2007 9:37 pm
Location: Mumbai, India

Re: Pass username and password to another page

Post 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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Pass username and password to another page

Post 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/>";
?>
 
Post Reply