Jump to content

[SOLVED] Logout Script


TheJoey

Recommended Posts

This is a login class I wrote a long time ago, hope it helps you:

 

class login{

var $response;

function set_user_login($username, $password)
{
$username=mysql_real_escape_string($username);
$password=mysql_real_escape_string($password);

     $query = "select salt from user where username='$username' limit 1";
     $result = mysql_query($query);

     if (mysql_num_rows($result) > 0)
     { 

          $user = mysql_fetch_array($result);

          $encrypted_pass = md5(md5($password).$user['salt']);

          $query = "select ID, username from user where username='$username' and password='$encrypted_pass'";
          $result = mysql_query($query);

          if (mysql_num_rows($result) > 0)
          {
               $user = mysql_fetch_array($result);
               $userid = $user['ID'];
               $encrypted_id = md5($user['userid']);
               $encrypted_name = md5($user['username']);

               $_SESSION['userid'] = $userid;
               $_SESSION['username'] = $username;
               $_SESSION['encrypted_id'] = $encrypted_id;
               $_SESSION['encrypted_name'] = $encrypted_name;

               $this->response = 'Correct';
          }
          else
          { 
               $this->response = 'Invalid Password';
          }
     }
     else
     {
          $this->response = 'Invalid Username';
     } 
}

function get_user_login()
{
return $this->response;
}

function set_user_logout()
{
     session_unset ();
     session_destroy ();
 echo"You have been successfully logged out, you will be redirected shortly.";
 echo"<META HTTP-EQUIV=\"Refresh\" Content=\"2;URL=index.php\">\n";
}

}

Link to comment
https://forums.phpfreaks.com/topic/177098-solved-logout-script/#findComment-933787
Share on other sites

Redirecting You Now

Warning: Cannot modify header information - headers already sent on line 48

 

im getting this error

for this code

its included in the body of my html code.

 

	  <?php
  unset($_SESSION['loginsuccessfull']);
  echo 'Redirecting You Now';
  header('location : ../../index.php');
  ?>

Link to comment
https://forums.phpfreaks.com/topic/177098-solved-logout-script/#findComment-934131
Share on other sites

headers can only be sent before output has begun, echo causes output (obviously, thats it's whole point :)) so you cannot use the header function after using echo. Incidently there would be no point in echo'ing that to the screen anyway as the redirect is instantaneous, so just remove the echo statement. You should also put exit; on the line below the redirect as the script will continue to run before the redirect otherwise.

Link to comment
https://forums.phpfreaks.com/topic/177098-solved-logout-script/#findComment-934252
Share on other sites

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.