Jump to content

[SOLVED] deleted my cookies and now my site doesnt work :(


Recommended Posts

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>

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

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.