session management

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
outsider
Forum Newbie
Posts: 3
Joined: Tue Feb 17, 2004 3:51 pm
Contact:

session management

Post by outsider »

how can check if user & password, and then if password is true how can i pass username into a new page?
like this:

username: outsider
password: admin

welcome outsider,
....
....
....

or /* if pass is not true */

wrong password,
...
...
...
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

<?php 
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if($username="outsider" && $password=="admin"){
  $_SESSION['username'] = $username;
  $_SESSION['password'] = $password;
  echo "Welcome " . $username;
}
else {
  echo "Incorrect Username/Password combination.";
}
?>
outsider
Forum Newbie
Posts: 3
Joined: Tue Feb 17, 2004 3:51 pm
Contact:

Post by outsider »

thank you, that worked well
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Nice explainations always work well ;)

Good Luck outsider, we want to see you more here ;)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

outsider if you check here again, please change this line:

Code: Select all

if($username="outsider" && $password=="admin"){
to this:

Code: Select all

if($username=="outsider" && $password=="admin"){
I forgot 1 equals sign. It's no big deal since it's only the username (and what good is a username without a password?) but if you were to make it dynamic, it would check the results against the password for 'outsider'.
Post Reply