Page 1 of 1
[SOLVED] creating a log out
Posted: Fri Feb 11, 2005 3:14 pm
by zmurf
i've created a database, a table, has username, email, password,first_name,last_name. i'm trying to keep it simple couse too much info makes me mistake.
i,ve created a index.php - includes a conn.php that checkes if i'm logged or not. if not includes a login.php : login form and a register link.
register php is ok, i can register and gives me the index.php with the stuff i wanna see.
now - write in browser:
http://localhost/index.php I AM ALLWAYS LOGGED IN
how do i create a log out thingy? my tutorial is about 800 pages long and ctrl+f doesnt find anything

((
p.s. and maybe the regiter can not log me in auto but send me to the login page ?
feyd | YELLING IS UNCALLED FOR!!!
Posted: Fri Feb 11, 2005 3:19 pm
by Todd_Z
Um... well considering you included no information about the nature of your system, I will assume that you are using normal session variables to determine whether you are logged in or not. The following is a simple solution:
Code: Select all
if ( $_GETї"Logout"] ) {
unset($_SESSIONї"Username"]);
unset($_SESSIONї"Password"]);
}
Hope this helps...
this is unlogged.php included in index.php
Posted: Fri Feb 11, 2005 5:15 pm
by zmurf
Code: Select all
<?php session_start();
include "conn.php";
if (isset($_POSTї'submit']))
{
$query = "SELECT username, password FROM users WHERE username = '" .$_POSTї'username'] . "' AND password = (password('" . $_POSTї'password']
. "'));";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 1)
{
$_SESSIONї'user_logged'] = $_POSTї'username'];
$_SESSIONї'user_password'] = $_POSTї'password'];
header ("Refresh: 5; URL=" . $_POSTї'redirect'] . "");
echo "You are being redirected to your original page request!<br>";
echo "(If your browser doesn’t support this, <a href="" .$_POSTї'redirect']. "">click here</a>)";
}
else
{
?>
<html>
<head>
<title>not logged</title>
</head>
<body>
Invalid Username and/or Password<br>
Not registered? <a href="register.php">Click here</a> to register.<br>
<form action="unlogged.php" method="post">
<input type="hidden" name="redirect" value="<?php echo $_POSTї'redirect'];?>">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
<?
}
}
else
{
if ($_SERVERї'HTTP_REFERER'] == "" || $_SERVERї'HTTP_REFERER'] == "http://localhost/1counterstrike/index.php")
{
$redirect = "index.php";
}
else
{
$redirect = $_GETї'redirect'];
}
?>
<html>
<head>
<title>not logged</title>
</head>
<body>
Login below by supplying your username/password...<br>
Or <a href="register.php">click here</a> to register.<br><br>
<form action="unlogged.php" method="post">
<input type="hidden" name="redirect" value="<? echo $redirect; ?>">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
<?php
}
?>
this is my index
Posted: Fri Feb 11, 2005 5:18 pm
by zmurf
Code: Select all
<?php session_start();
include "conn.php";
?>
<html>
<head>
<title>Counter Strike Mania</title>
</head>
<body>
<?php
if ($_SESSIONї'user_logged'] == "" || $_SESSIONї'user_password'] == "")
{
echo '<center>';
include "unlogged.php";
echo "</center>";
}
else
{
include "logged.php";
}
?>
</body>
</html>
and the logged is just some file that says bla bla
i was trying to put there a button (or anywhere else ) that loges me out
anyways its about 1;18 am here, so good night and thanks
feyd |
sry feyd

Posted: Fri Feb 11, 2005 5:27 pm
by feyd
please post code correctly
