...

View Full Version : Login Control in my php



deshi2003
03-11-2009, 04:46 PM
Hi i am developing a site and it is my first professional project. here i am using login control by checking database as usual.for redirection like accessing restricted page without login i used a session variable like $_SESSION['user'] .if it is not set (session variable) by checking isset() then i redirect to login page using Header() function.

for session to work i used session_start() (as in php.ini automatic session start is off)at starting of each page.

one thing i am not understanding what should i do when user logout from my page.

should i destroy session by using session_destroy() or unset() session[user] variable or completely follow another strategy to login as it is not the good way of login control please please hel this is my first post in this site.

ninnypants
03-11-2009, 05:17 PM
you can use both and destroy the sessions cookie too


unset($_SESSION['user']);

if(isset($_COOKIE[session_name()]))
setcookie(session_name(), '', time() - 1000);
session_destroy();

IamHe
03-11-2009, 05:34 PM
<?php
session_start();
unset($_SESSION['user']);
header("Location: login.php");
exit()
?>




simple logout script, just needs saving as logout.php and linking up :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum