Jump to content

learning sessions properly......


redarrow

Recommended Posts

 

I am currently going thorw all the session page at php.net to learn all the fucntions........

 

Hi there i created this script where if a user refreshes the page more then

20 times there a error message for pratice only............

 

For a real online test the error message would be a header redirect........

 

 

Can you see a easer way or do you think it will work........

<?php session_start();


$_SESSION['address']=$_SERVER['REMOTE_ADDR'];

$_SESSION['current_address']=$_SESSION['address'];

if( ($_SESSION['count'] >21) && ($_SERVER['REMOTE_ADDR']." ")){

session_destroy();
}

if(!isset($_SESSION['count'] ) && !isset($_SESSION['address'])){

$_SESSION['count']=0;

}else{

$_SESSION['count']++;

echo $_SESSION['count'];

}

if(($_SESSION['count']=="20")&& ($_SESSION['address']=="".$_SESSION['current_address']."")){

echo "session's are deleted and the ip of ".$_SESSION['address']." 
Landed on my page more then 20 times";

exit;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/
Share on other sites

online vesion........

 

<?php session_start();


$_SESSION['address']=$_SERVER['REMOTE_ADDR'];

$_SESSION['current_address']=$_SESSION['address'];

if( ($_SESSION['count'] >21) && ($_SERVER['REMOTE_ADDR']." ")){
   
   session_destroy();
}

if( ($_SESSION['count'] ) && ($_SESSION['current_address']." ")){
   
header('location: http://www.google.com');

}

if(!isset($_SESSION['count'] ) && !isset($_SESSION['address'])){

$_SESSION['count']=0;

}else{

$_SESSION['count']++;

echo $_SESSION['count'];

}

if(($_SESSION['count']=="20")&& ($_SESSION['address']=="".$_SESSION['current_address']."")){

header('location: http://www.google.com');

session_detory();

exit;

}

?>

This should keep the user out off the page untill the session dies.......

 

 

does it work please.............

 

<?php session_start();

if($_SESSION['address']){

header('location: http://www.google.co.uk');	
}

$_SESSION['address']=$_SERVER['REMOTE_ADDR'];

$_SESSION['current_address']=$_SESSION['address'];

if( ($_SESSION['count'] >21) && ($_SERVER['REMOTE_ADDR']." ")){
   
   session_destroy();
}

if(!isset($_SESSION['count'] ) && !isset($_SESSION['address'])){

$_SESSION['count']=0;

}else{

$_SESSION['count']++;

echo $_SESSION['count'];

}

if(($_SESSION['count']=="20")&& ($_SESSION['address']=="".$_SESSION['current_address']."")){

header('location: http://www.google.co.uk');

session_detory();

exit;

}

?>

 

session_cache_limiter('address');

 

session_cache_limiter('count');

 

$cache_limiter = session_cache_limiter();

 

session_cache_expire(1);

$cache_expire = session_cache_expire();

 

 

The above code example should only allow the session of count and address

set for 1 min am i write here...........

 

 

 

<?php 

session_cache_limiter('address');

session_cache_limiter('count');

$cache_limiter = session_cache_limiter();

session_cache_expire(1);
$cache_expire = session_cache_expire();

session_start();

$_SESSION['address']=$_SERVER['REMOTE_ADDR'];

$_SESSION['current_address']=$_SESSION['address'];

if( ($_SESSION['count'] >21) && ($_SERVER['REMOTE_ADDR']." ")){
   
   session_destroy();
}

if(!isset($_SESSION['count'] ) && !isset($_SESSION['address'])){

$_SESSION['count']=0;

}else{

$_SESSION['count']++;

echo $_SESSION['count'];

}

if(($_SESSION['count']=="20")&& ($_SESSION['address']=="".$_SESSION['current_address']."")){

header('location: http://www.google.co.uk');

session_detory();

exit;

}

?>

this should work afther 1 min let me back to the page  why is it buggy.....

 

dosent work why......

 

<?php 

session_cache_limiter ('private, must-revalidate');   // for firefox.....

$cache_limiter = session_cache_limiter('address'); // session varable

session_cache_expire(1);  //time to destroy session

if($cache_limiter){ //if session alive

header('location: http://www.google.co.uk'); // go to this address otherwise dies let me in
}

session_start(); // start a session when the session dies......
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.