PDA

View Full Version : PHP help...



Coda
25-08-2008, 12:33 PM
Right i have a login script but when the user logs out i want it to redirect to a new page, not using the html redirection probably header() is the best method.

I know how to use header's but i just dont know where to place it in this code so that once the user is logged out then it will execute the redirection.

heres the code:


if($user!="" && $pass!="" && $d!="logout") {
$mdc = mysql_query("SELECT * FROM user WHERE user = '".addslashes($user)."' AND pass = '".addslashes($encrypt_pass)."'"); $usrd = mysql_fetch_array($mdc);
if($usrd[id]!="") {

$_SESSION[user] = $user; $_SESSION[pass] = $pass; $lg="ok";
mysql_query("UPDATE user SET online='".time()."' WHERE id='".$usrd[id]."'");

} else { session_unset(); $lg=""; }
} else { session_unset(); $lg=""; }

Invent
25-08-2008, 12:38 PM
<?php

if( $user != '' && $pass != '' && $d != 'logout' )
{

$mdc = mysql_query( "SELECT * FROM `user` WHERE `user` = '" . addslashes( $user ) . "' AND `pass` = '" . addslashes( $encrypt_pass ) . "'" );
$usrd = mysql_fetch_array( $mdc );

if( $usrd[ 'id' ] != '' )
{

$_SESSION[ 'user' ] = $user;
$_SESSION[ 'pass' ] = $pass;
$lg = 'ok';

mysql_query( "UPDATE `user` SET `online` = '" . time() . "' WHERE `id` = '" . $usrd[ 'id' ] . "'");

}
else
{

session_unset( );
$lg = '';

}

}
else
{

session_unset( );
$lg = '';

header( 'Location: logout.php' );

}

?>
Try that.

Want to hide these adverts? Register an account for free!