k3v0 Posted August 24, 2008 Share Posted August 24, 2008 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 More sharing options...
Aeglos Posted August 25, 2008 Share Posted August 25, 2008 Try changing the format of all the cookie values, from this: $userValue = "$result[username]"; to this: $userValue = $result['username']; Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624582 Share on other sites More sharing options...
k3v0 Posted August 25, 2008 Author Share Posted August 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624604 Share on other sites More sharing options...
coldfiretech Posted August 25, 2008 Share Posted August 25, 2008 Did you try using the SetCookie function? $userValue = $result['username']; setcookie("userValue", $userValue); Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624608 Share on other sites More sharing options...
k3v0 Posted August 25, 2008 Author Share Posted August 25, 2008 Yes, that's what is in the code right now... It still isn't working... Any Ideas? Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624615 Share on other sites More sharing options...
coldfiretech Posted August 25, 2008 Share Posted August 25, 2008 Are you trying to set the cookie after the <html> tag in your file? or is it in just a straight php file? Im pretty new, just started learning php last week but here is a great website with alot of good info http://www.w3schools.com/php/php_cookies.asp Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624619 Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 try doing this on a page after cookies are set <?php print_r($_COOKIE); ?> Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624621 Share on other sites More sharing options...
k3v0 Posted August 25, 2008 Author Share Posted August 25, 2008 try doing this on a page after cookies are set <?php print_r($_COOKIE); ?> I get this for the output Array ( [AUTH] => 1 ) And it is just a straight php file not a html file coldfiretech Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624659 Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 which means as u stated 1 cookie being set Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624661 Share on other sites More sharing options...
k3v0 Posted August 25, 2008 Author Share Posted August 25, 2008 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? Link to comment https://forums.phpfreaks.com/topic/121158-php-login-script-help/#findComment-624662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.