Jump to content

Check if logged in function


ravravrav

Recommended Posts

Hi I have this code which isn't fully complete but I'd like to change it in a function so I can call it whenever I need to check if a user is logged in or not:

I'd like to put it into something called logincheck.php...

[code]
//Checks if there is a login cookie
if(isset($_COOKIE['my_hash']))
//if there is, it checks to see if my_hash = userhash
{
$c_user = $_COOKIE['my_username'];
$c_hash = $_COOKIE['my_hash'];
       
$check = mysql_query("SELECT * FROM Users WHERE Username = '$c_user'")or die(mysql_error());

while($info = mysql_fetch_array( $check ))     
{
if ($c_hash != $info['Userhash']) // not logged in
{

}
else // logged in already
{

header("Location: users.php");
}
}
}
[/code]


Any ideas how I would change it and how to call it from other pages?
Thx
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.