Jump to content

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

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.