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&#1111;'submit']))
&#123;
$query = "SELECT username, password FROM users WHERE username = '" .$_POST&#1111;'username'] . "' AND password = (password('" . $_POST&#1111;'password']
. "'));";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 1)
&#123;
$_SESSION&#1111;'user_logged'] = $_POST&#1111;'username'];
$_SESSION&#1111;'user_password'] = $_POST&#1111;'password'];
header ("Refresh: 5; URL=" . $_POST&#1111;'redirect'] . "");
echo "You are being redirected to your original page request!<br>";
echo "(If your browser doesn’t support this, <a href="" .$_POST&#1111;'redirect']. "">click here</a>)";
&#125;
else
&#123;
?>
<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&#1111;'redirect'];?>">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
<?
&#125;
&#125;
else
&#123;
if ($_SERVER&#1111;'HTTP_REFERER'] == "" || $_SERVER&#1111;'HTTP_REFERER'] == "http://localhost/1counterstrike/index.php")
&#123;
$redirect = "index.php";
&#125;
else
&#123;
$redirect = $_GET&#1111;'redirect'];
&#125;
?>
<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
&#125;
?>

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&#1111;'user_logged'] == "" || $_SESSION&#1111;'user_password'] == "")
	&#123;
	echo '<center>';
	include "unlogged.php";
	echo "</center>";
	&#125;
	else
	&#123;
	include "logged.php";
	&#125;
?>
</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 | :roll:

sry feyd :)

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