bhavin_85 Posted February 19, 2007 Share Posted February 19, 2007 hey guys i deleted my cookies in my browser and the site im developing now doesnt work ??? when i open the login page and enter the correct details it just refreshes the default page...this shouldnt happen because if the user enters an incorrect username or password it should redirect them to a page that tells them they have entered an incorrect username/password any1 ahve any idea what ive done? <? session_start(); if(isset($_GET['reg'])){ $reg=$_GET['reg']; }else{ $reg=""; } if($reg==1){ $msg1="<font color=\"#FF0000\"><b>Your details have been added, please login</b></font>"; }elseif($reg==2){ $msg1="<font color=\"#FF0000\"><b>You have been successfully logged out.</b></font>"; } if(isset($_POST['submit'])){ if( empty($_POST['uname']) && (empty($_POST['upass']))){ header ("Location:Messages.php?msg=1" ); exit(); } //transfer to shorter var $n=$_POST['uname']; $p=$_POST['pwd']; include('config.php'); $sql="SELECT * FROM customer WHERE uname='$n' AND pwd=MD5('$p')"; $query=mysql_query($sql) or die("Queryfailed:".mysql_error()); if (mysql_num_rows($query) != 0) { $row = mysql_fetch_assoc($query); $_SESSION['cust_id'] = $row['cust_id']; $_SESSION['first_name'] = $row['first_name']; $_SESSION['surname'] = $row['surname']; $_SESSION['address1'] = $row['address1']; $_SESSION['address2'] = $row['address2']; $_SESSION['town'] = $row['town']; $_SESSION['county'] = $row['county']; $_SESSION['postcode'] = $row['postcode']; $_SESSION['date_of_birth'] = $row['date_of_birth']; $_SESSION['home_number'] = $row['home_number']; $_SESSION['mobile_number'] = $row['mobile_number']; $_SESSION['points'] = $row['points']; $_SESSION['access_level'] = $row['access_level']; $_SESSION['uname'] = $row['uname']; $_SESSION['status'] = 'logged'; if ($_SESSION['access_level'] == '1') { header ("Location: http://localhost/PBL/welcome1.php"); } elseif ($_SESSION['access_level'] == '2') { header ("Location: http://localhost/PBL/welcome2.php"); } elseif ($_SESSION['access_level'] == '3') { header ("Location: http://localhost/PBL/welcome3.php"); exit; } } else { $_SESSION['status'] = 'not logged'; header("Location:Messages.php?msg=2" ); exit(); } } ?> <html> <head> <title>PBL Jewellers Ltd.</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#030102" text="#666666"> <table width="670" height="546" border="0" align="center" bordercolor="#000000"> <tr> <td colspan=3> <img src="images/banner1.png" width="670" height="158" align="top"> </td> </tr> <tr> <td rowspan="3" align="right"> <img src="images/ring.png" width="183" height="163"> </td> </tr> <tr> <form name="form1" method="post" action=<? echo $_SERVER['PHP_SELF'];?>> <td valign="top" align="center"> <input name="uname" type="text" id="uname" value="email address" size="18"> <input name="pwd" type="password" id="pwd" value="password" size="18" > <input name="submit" type="submit" value="Login"> </form> <td rowspan="2"></td></tr> <tr> <td valign="top" align="center"><img src="images/box.png"></tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/ Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 I personally would change the way you do your "login script". Basically you're using wayy to many sessions when you only need to set 1 session, anyway i hoep this helps.. <?php ob_start(); // this allowed headers to be used even though they are set! session_start(); include("config.php"); //database config here if(empty($_POST['username'])) { echo("username must be set"); exit; } if(empty($_POST['password'])) { echo("password must be set"); exit; } $SQL = mysql_query("SELECT * FROM `table` WHERE `username`='".$_POST['username']."' AND `password`='".md5($_POST['password'])."'"); if(!mysql_num_rows($SQL)) { die("Sorry, incorrect username/password combination"); } else { while($data = mysql_fetch_array($SQL)) { $_SESSION['UID']=$data['user_id']; //the user_id = the id field of your users table header("location: ".$_SERVER['php_self']); } } ob_end_flush(); //flushes the ob_start(); ?> then you can use the UID Session to fetch futher information at any time Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/#findComment-188542 Share on other sites More sharing options...
bhavin_85 Posted February 19, 2007 Author Share Posted February 19, 2007 ive jsut hada crack at usin that code, but it doesnt even produce the page ??? it just says a username must be set, its not gettin past the first if statement....where should i move that statement to? Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/#findComment-188555 Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 the problem is, you need to make sure that the $_POST['username'] and $_POST['password'] correspond to your html coding. if your form fields are named user and pass then change those to... $_POST['user'] and $_POST['pass'] i forgot to leave a comment. Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/#findComment-188564 Share on other sites More sharing options...
bhavin_85 Posted February 19, 2007 Author Share Posted February 19, 2007 i already tried that, but it seems that the code isnt going past the first if statement <?php ob_start(); // this allowed headers to be used even though they are set! session_start(); include("config.php"); //database config here if(empty($_POST['uname'])) { echo("username must be set"); exit; } if(empty($_POST['pwd'])) { echo("password must be set"); exit; } $SQL = mysql_query("SELECT * FROM customer WHERE `uname`='".$_POST['uname']."' AND `pwd`='".md5($_POST['pwd'])."'"); if(!mysql_num_rows($SQL)) { die("Sorry, incorrect username/password combination"); } else { while($data = mysql_fetch_array($SQL)) { $_SESSION['cust_id']=$data['cust_id']; //the user_id = the id field of your users table header("location: ".$_SERVER['php_self']); } } ob_end_flush(); //flushes the ob_start(); ?> <html> <head> <title>PBL Jewellers Ltd.</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#030102" text="#666666"> <table width="670" height="546" border="0" align="center" bordercolor="#000000"> <tr> <td colspan=3> <img src="images/banner1.png" width="670" height="158" align="top"> </td> </tr> <tr> <td rowspan="3" align="right"> <img src="images/ring.png" width="183" height="163"> </td> </tr> <tr> <form name="form1" method="post" action=<? echo $_SERVER['PHP_SELF'];?>> <td valign="top" align="center"> <input name="uname" type="text" id="uname" value="email address" size="18"> <input name="pwd" type="password" id="pwd" value="password" size="18" > <input name="submit" type="submit" value="Login"> </form> <td rowspan="2"></td></tr> <tr> <td valign="top" align="center"><img src="images/box.png"></tr> </table> </body> </html> as you can see my username is set as uname and password is set as pwd....i changed that but im still gettin the same error of: username must be set Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/#findComment-188568 Share on other sites More sharing options...
xyn Posted February 19, 2007 Share Posted February 19, 2007 try !isset( instead of empty Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/#findComment-188574 Share on other sites More sharing options...
bhavin_85 Posted February 19, 2007 Author Share Posted February 19, 2007 its ok mate that didnt work, but ive made the code work by adjusting a few things...cheers Quote Link to comment https://forums.phpfreaks.com/topic/39152-solved-deleted-my-cookies-and-now-my-site-doesnt-work/#findComment-188633 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.