Hi, I’m currently working on an image hosting site. I want users to be able to be logged in to enhance certain things. I’m a little new to writing PHP, and I’m having a problem.
http://trollin.info/ - if you try to make an account, you’ll find that it all works but when you log in and refresh the page you’re logged out again.
Here’s the code for my login on index.php:
<?
/*Use of Sessions*/
if(!session_id())
session_start();
header("Cache-control: private"); //avoid an IE6 bug (keep this line on top of the page)
$login='<form method="post" action="index.php" >
Login:<br />
<input type="text" name="login" /><br />
Password:<br />
<input type="password" name="pass" /><br />
<input type="submit" value="Sign in" /><br />
</form>
<a href="signup.html">Sign up</a>';
/*simple checking of the data*/
if(isset($_POST['login']) && isset($_POST['pass']))
{
/*Connection to database logindb using your login name and password*/
$db=mysql_connect('localhost','loginuser','loginpass') or die(mysql_error());
mysql_select_db('logindb');
/*additional data checking and striping*/
$_POST['login']=mysql_real_escape_string(strip_tags(trim($_POST['login'])));
$_POST['pass']=mysql_real_escape_string(strip_tags(trim($_POST['pass'])));
$q=mysql_query("SELECT * FROM login WHERE login='{$_POST['login']}' AND pass='{$_POST['pass']}'",$db) or die(mysql_error());
/*If there is a matching row*/
if(mysql_num_rows($q) > 0)
{
$_SESSION['login'] = $_POST['login'];
$login='Welcome back '.$_SESSION['login'];
}
else
{
$login= 'Incorrect username or password';
}
mysql_close($db);
}
//you may echo the data anywhere in the file
echo $login;
?>
I did use a tutorial for it. I need help with two things:
-
Staying online after a refresh.
-
A logout button.
Thanks!