Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login page

Status
Not open for further replies.

anuj576

Programmer
Jul 20, 2008
14
0
0
IN
Hey guys,
I have developed a web application in which i have applied sessions. The session starts when the user successfully log's in and ends when the user log's out. But the problem is that when the user log's out he can go back to the page which is wrong.
Please give some suggestions.
 
Can you please tell me what is nonce???
I've heard it for the first time..
 
do you destroy the session cookies when the user logs out?
if not they would still be valid untill the user closes the browser

Code:
	$_SESSION = array(); // Destroy the variables.
	session_destroy(); // Destroy the session itself.
	setcookie (session_name(), '', time()-300, '/', '', 0); // Destroy the cookie.

should be close enough.
 
the session method doesn't work because if you press the back button the browser will resubmit the login form. and then the session will be regenerated.

 
nope. a nonce is a Number Used Once.

what i do is:

1. insert a hidden field in the login form.
2. store the value of the hidden field in a session ID (note that i need sessions ON for this)
3. on submission test to see whether the session value exists and whether it equals the submitted post value.
4. if it doesn't then the submission is spoofed
5. if it does, i remove the value from the session store

the values are always globally unique ids.

something like this is the code i use
Code:
<?php
class nonce{
	public function __construct(){
		if (session_id() == '') session_start();
	}
	public function getNonce($type='default'){
		if (isset($_SESSION['nonce'][$type])){
			//
		} else {
			$_SESSION['nonce'][$type] = sha1 (uniqid('nonce', true));
		}
		return $_SESSION['nonce'][$type] ;
	}
	public function checkNonce($type='default'){
		if (empty($_SESSION['nonce'][$type])){
			return false;
		}
		if (empty($_REQUEST['nonce'])){
			return false;
		}
		if ($_SESSION['nonce'][$type] == $_POST['nonce']){
			unset ($_SESSION['nonce'][$type]);
			return true;
		} else {
			return false;
		}
	}

	public function insertNonceField($type){
		$value = $this->getNonce($type);
		return <<<HTML
	<input type="hidden" name="nonce" value="$value" />
HTML;
	}
}
?>
 
Is what I came with in the same area of result?

Code:
//login 

session_start();

////// adding security we create the initial $need to match from here ////////

	$str=$_SERVER['HTTP_USER_AGENT'];
	$str .='asasasas';
	$need_to_match= md5($str);
	$_SESSION['need_to_match']=$need_to_match;
	$need_to_match=$_SESSION['need_to_match'];
	
//any landing page

$str=$_SERVER['HTTP_USER_AGENT'];
	$str .='asasasas';
	$need_to_match2= md5($str);
	
	$need_to_match=$_SESSION['need_to_match'];

	if(isset($_SESSION['need_to_match']) && $need_to_match === $need_to_match2)
	{// OK
	else unset etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top