[SOLVED] creating a log out

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zmurf
Forum Newbie
Posts: 10
Joined: Wed Jan 26, 2005 8:15 am
Location: romania
Contact:

[SOLVED] creating a log out

Post 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!!!
Last edited by zmurf on Sat Feb 12, 2005 8:04 am, edited 1 time in total.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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...
zmurf
Forum Newbie
Posts: 10
Joined: Wed Jan 26, 2005 8:15 am
Location: romania
Contact:

this is unlogged.php included in index.php

Post 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;
?>
zmurf
Forum Newbie
Posts: 10
Joined: Wed Jan 26, 2005 8:15 am
Location: romania
Contact:

this is my index

Post 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 :)
Last edited by zmurf on Fri Feb 11, 2005 5:31 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

please post code correctly :evil:
Post Reply