Current location: Hot Scripts Forums » Programming Languages » PHP » Securing a Webpage: User Must Login


Securing a Webpage: User Must Login

Reply
  #1 (permalink)  
Old 10-20-11, 06:40 AM
sby247 sby247 is offline
New Member
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Securing a Webpage: User Must Login

I have a problem with my webpage secure script. Even after logout, wen I hit the back button on my browser, I can still access the secure page. I can still even access the assigned page without login instead of redirecting to "login.php". I don't know what might be wrong with the variable or scripting. I have tried the "||", "&&" and "or" variable and it work. Here is the secure page script.


<?php
//Start session
session_start();

//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['login']) xor (trim($_SESSION['login']) == '')) {
header("location: login.php");
exit();
}
?>


Here is the logout out script :

<?php
//Start session
session_start();
session_destroy();

//Unset the variables stored in session
unset($_SESSION['login']);

//Redirect use to login page
header("location: login.php");

Please I need to get this resolve ASAP. Thanks in anticipation.
Reply With Quote
  #2 (permalink)  
Old 10-21-11, 10:50 PM
nishchal_619 nishchal_619 is offline
New Member
 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
i think you shuold use cookie for this but remember cookie is not so secure until you encrypt it, use crypt() function to encrypt the data in the variable (dont use md5 hasing because it can be decrypted) you can easily make your method
suppose you have variable $user then to encrypt it,
$enc=crypt($password,"wrt what you are encrypting");

since you can give the second variable and it is secure in your mind, even if some one view cookie, he wont be able to understand what is that, then you need to store cookie when username and password matches
setcookie("username",$user,time()+3600);
//i did 3600 to expire the cookie in 1 hrs, means user can use up to 1 hour, (note time is in seconds) you can make keep me logged in box and set the expiration time to 1month and if not then dont give the expiration time just leave up to setcookie("username",$user) in this case cookie will be cleared as soon as user exits the browser
now we have to redirect to home page but in the home page you need to check for the cookie if it is set and password matches if cookie is present and encrypted data in cookie is equal to the data in the database after data of data is encrypted then password matches
suppose encrypted data of nishchal is
ladfoiafe;po with respect to some keyword, then we have to acess the database, suppose password is nishchal in the database also so if i encrypt the "nishchal" which is in database then encrypted data in cookie will be equal to the encrypted data just now then you may make a good site this facebook and i also in many websites have used this technique, this is a professional method of developing a website
Reply With Quote
  #3 (permalink)  
Old 10-24-11, 10:10 AM
kameshoddanchatram kameshoddanchatram is offline
New Member
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
KAMESHsoft - login script

Halow i am kamesh i saw that you have anproblem with your login script you had made a mistake
at "or " function you had type xor .
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
logging into website (sending form data) gnznroses Visual Basic 1 12-05-05 05:32 PM
single login using multiple user tables jersey Script Requests 0 09-16-05 08:32 PM
Preventing multiple user from loging in using the same username and password digioz PHP 2 09-14-05 01:53 PM


All times are GMT -5. The time now is 08:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.