...

View Full Version : Login Script??



angst
07-12-2005, 04:32 PM
Hello,

I need to build a simple login script, i have 3 accounts stored in a mysql data base, and i would like to maybe use cookies, but not sure if session would be better.

could someone please show me an example of a login script that has these functions?

thanks in advance for your time!

-Ken

angst
07-12-2005, 07:41 PM
ok, what if i were to just hardcode the username and password?
could some one just show me the correct syntax?
I know in ASP i was just able to use AND, but that doesn't seem to work here, and i haven't been able to find anything with google searches..



<?php

$user = $_POST['user'];
$pass = $_POST['pass'];

if ( $user == "admin" AND $pass == "admin" ) {

header("Location: admin.php?edit");

} else {

header("Location: index.php?error=login");


}


?>

Nightfire
07-12-2005, 07:48 PM
AND should work, but I think it might be depreciated. Not sure though. Anyway, try using &&


if($user == "admin" && $pass=="admin")(

Fou-Lu
07-12-2005, 07:58 PM
Yeah, weird, AND should work for you.
Its not that its depreciated, it just has a lower precidence when it comes to comparing && and 'AND'. If you know your mathmatics well enough, program like your writting an equation, this will give you the same output.
You should use some sessions though:


<?php
session_start();

if (empty($_SESSION['username']))
{
if ($_POST['user'] == 'admin' AND $_POST['password'] == 'admin')
{
$_SESSION['username'] = $_POST['user']; // From this, should be admin.
$_SESSION['password'] = $_POST['password'];
header("location: admin.php?edit");
}
else
{
header("location: index.php?error=login");
}
}
else
{
header("location: admin.php?edit");
}
?>

Or something of the sorts.

angst
07-12-2005, 09:05 PM
ok, i'd like to use the session script,

but how do I then check for the session on the pages after login?


thanks again for all you help!
-Ken


ps: yah, && worked just fine:-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum