Jump to content

PHP Login Script HELP!!!


k3v0

Recommended Posts

Please help,  I have been messing with this code for about 3 days and for some reason, it will only set the first cookie and not the ones following that.  I have 2 files, login.php and authorize.php.

 

I would appreciate ANY help in this.

 

The following code is the login.php which I don't think there is a problem with.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="support.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body><table id="login_table" width="300" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="login" method="post" action="authorize.php">
<td>
<table width="100%" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Client Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

 

 

The following is where I believe the actual problem is...just not sure what exactly it is...PLEASE HELP!!!

<?php
include('include/db.php');

// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM `client_login` WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row

if($count==1){
// Register $username, $password and redirect to file "welcome.php"
								# set cookie parms - AUTH
										$authValue = 1;
										setcookie("AUTH", $authValue);

								# set cookie parms - USER
										$userValue = "$result[username]";
										setcookie("USER", $userValue);

								# set cookie parms - USER
										$first_name_sess = "$result[first_name]";
										setcookie("FIRST_NAME_SESS", $first_name_sess);  

								# set cookie parms - USER
										$last_name_sess = "$result[last_name]";
										setcookie("LAST_NAME_SESS", $last_name_sess);

								# set cookie parms - EID
										$eData = "$result[EID]";
										setcookie("EID", $eData);
header("location:welcome.php");
}
else {
//If wrong username, redirect to login.php after 5 seconds.
echo 'Wrong Username or Password<br />
					<form name="redirect">
					You will be redirected to the homepage in
					<input style="border:0px; width:13px; text-align:right;" type="text" name="redirect2" />
					seconds
					</form>



					<script>
					var targetURL="login.php"

					//change the second to start counting down from

					var countdownfrom=5


					var currentsecond=document.redirect.redirect2.value=countdownfrom+1
					function countredirect(){
					if (currentsecond!=1){
					currentsecond-=1
					document.redirect.redirect2.value=currentsecond

					}
					else{
					window.location=targetURL
					return
					}
					setTimeout("countredirect()",1000)
					}

					countredirect()
					//-->
					</script>';

}
?>

Link to comment
https://forums.phpfreaks.com/topic/121158-php-login-script-help/
Share on other sites

I don't know why this still isn't working.

 

It isn't registering the cookies, because I am trying to echo the cookie value in welcome.php with the following code:

 

<?php 
$eid = $_COOKIE['EID'];
$fn = $_COOKIE['FIRST_NAME_SESS'];
$ln = $_COOKIE['LAST_NAME_SESS'];
$user = $_COOKIE['USER'];
$authorize = $_COOKIE['AUTH'];
echo $eid;
echo $fn;
echo $ln;
echo $user;
echo $authorize;
?>

 

The only one it echo's is the $authorize because it is not a variable in authorize.php.

 

Anything else you can think of, I am open to ideas...

 

I do appreciate the fix you told me about already.

 

I think that was wrong with it too, but something is keeping it from registering the cookies, it will register the AUTH cookie, but not the others....Not sure what to do.

Well, if you look at my code, I have set multiple cookies, but for some reason, any cookie with the value being a variable

i.e.

<?php
$first_name_sess = $result['first_name'];
setcookie("FIRST_NAME_SESS", $first_name_sess);  
?>

 

it doesn't register the cookie and I am not sure why.

 

Any ideas on that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.