Jump to content

No sessions are being set in my login script :S


jamesxg1

Recommended Posts

<?php session_start();


error_reporting(E_ALL | E_NOTICE); 
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL ^ E_NOTICE);

include 'Database/Connection.php';

$userid = mysql_real_escape_string(intval($_POST['userid']));

$username = mysql_real_escape_string($_POST['username']);

$pass_word = mysql_real_escape_string($_POST['password']);

$password = md5($pass_word);

if (isset( $_SESSION['loggedin'] )) {

header('Location: Main.php');

}else{

if (isset($_POST['submit'])) {

if($username && $password && $userid) {

        $result = mysql_query($sql);

$sql = sprintf("SELECT * FROM `members` WHERE username = '$username' AND password = '$password' AND userid = '$userid'"); 
$result = mysql_query($sql);

$morerow = mysql_fetch_array($result);

if (mysql_num_rows($result) > 0) {
            
if ($morerow['level'] != "S") { 

          	 $_SESSION['loggedin']="TRUE"; 
          	 $_SESSION['username'] = $username;
          	 $_SESSION['level'] = $morerow['level'];
          	 $_SESSION['id'] = $morerow['id'];
          	 $_SESSION['lastname'] = $morerow['lastname'];
          	 $_SESSION['firstname'] = $morerow['firstname'];
          	 $_SESSION['email'] = $morerow['email'];

header('Location: Main.php');
          
          } else
            echo "<div align=\"center\"><font color=red> 
  		        <img src=\"images/exclam.PNG\"/><i>Your account has been suspended or banned by admin.</i></font></div>";
       }else{

          echo "<div align=\"center\"><font color=red> 
  		        <img src=\"images/exclam.PNG\"/><i>Invalid login<br>If you are a new user please register</i></font></div>";
       }

    }else{ 

      echo "<div align=\"center\"><font color=red> 
           <img src=\"images/exclam.PNG\"/><i> You must enter a username and password!</i></font></div>";
    }
    
  }
  

}

?>



  <form method="POST" action="<?php echo "$PHP_SELF"; ?>"> 
<p align="center">
 <b>User ID:</b> <input type="text" name="userid" size="20" maxlength="255" />
 </p>

     <p align="center">
 <b>Username</b> <input type="text" name="username" size="20" maxlength="255" />
 </p>
 <p align="center">
 <b>Password</b> <input type="password" name="password" size="20" maxlength="255" />
 </p>

    <p align="center">
  <input type="submit" name="submit" value="Submit">
  </p>
<br />

  </form>


 

i atleast need the $_SESSION['level'] to be set but nothing is setting :S

 

any help here guys ?

Link to comment
Share on other sites

trie this.

<?php session_start();


error_reporting(E_ALL | E_NOTICE); 
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL ^ E_NOTICE);

include 'Database/Connection.php';

$userid = mysql_real_escape_string(intval($_POST['userid']));

$username = mysql_real_escape_string($_POST['username']);

$pass_word = mysql_real_escape_string($_POST['password']);

$password = md5($pass_word);

if (isset( $_SESSION['loggedin'] )) {

header('Location: Main.php');

}else{

if (isset($_POST['submit'])) {

if($username && $password && $userid) {

        $result = mysql_query($sql);

$sql = sprintf("SELECT * FROM `members` WHERE username = '$username' AND password = '$password' AND userid = '$userid'"); 
$result = mysql_query($sql);

while($morerow = mysql_fetch_assoc($result){

if (mysql_num_rows($result) > 0) {
            
if ($morerow['level'] != "S") { 

              $_SESSION['loggedin']="TRUE"; 
              $_SESSION['username'] = $username;
              $_SESSION['level'] = $morerow['level'];
              $_SESSION['id'] = $morerow['id'];
              $_SESSION['lastname'] = $morerow['lastname'];
              $_SESSION['firstname'] = $morerow['firstname'];
              $_SESSION['email'] = $morerow['email'];

header('Location: Main.php');
          
          } else
            echo "<div align=\"center\"><font color=red> 
                <img src=\"images/exclam.PNG\"/><i>Your account has been suspended or banned by admin.</i></font></div>";
       }else{

          echo "<div align=\"center\"><font color=red> 
                <img src=\"images/exclam.PNG\"/><i>Invalid login<br>If you are a new user please register</i></font></div>";
       }

    }else{ 

      echo "<div align=\"center\"><font color=red> 
           <img src=\"images/exclam.PNG\"/><i> You must enter a username and password!</i></font></div>";
    }
    
  }
  

}
}
?>

Link to comment
Share on other sites

ok i changed it to lowercase and the other script that was supplyed didnt work :S

it wasn't the lowercase i was referring to .. lose the quotations to set a true/false var.

 

have you echo'd anything out to see if the proper variables are being passed .. is $_POST['submit'] working as planned?  'cause your sessions var's are only being set if you make it to them .. if the form is failing before they are set, they will not be set :S

 

add error_reporting(E_ALL); to the top of your script(s) so you can see what's going on (assuming you don't already have error_reporting on).  and test to make sure you are reaching your sql statement.

Link to comment
Share on other sites

ok i changed it to lowercase and the other script that was supplyed didnt work :S

it wasn't the lowercase i was referring to .. lose the quotations to set a true/false var.

 

have you echo'd anything out to see if the proper variables are being passed .. is $_POST['submit'] working as planned?  'cause your sessions var's are only being set if you make it to them .. if the form is failing before they are set, they will not be set :S

 

add error_reporting(E_ALL); to the top of your script(s) so you can see what's going on (assuming you don't already have error_reporting on).  and test to make sure you are reaching your sql statement.

 

lol ok thanks :),

and i havent no but i am assuming its working seeings as i get the correct errors if i enter the details wrong and it reffers me to the page that is set for if the login returns successfull i just dont understand why the sessions arent being set :S

Link to comment
Share on other sites

do you have session_start(); at the top of all the pages using sessions?

 

any page that uses sessions needs to have it at the top.

 

have you used sessions on that same server before?

 

yes every page has session_start();

 

and yes many times

Link to comment
Share on other sites

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.