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
https://forums.phpfreaks.com/topic/28474-check-if-logged-in-function/
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.