redarrow Posted October 10, 2008 Share Posted October 10, 2008 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/ Share on other sites More sharing options...
ngreenwood6 Posted October 10, 2008 Share Posted October 10, 2008 Have you tested it? There is only one way to find out if it will work or not. Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662134 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Author Share Posted October 10, 2008 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662150 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Author Share Posted October 10, 2008 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662167 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Author Share Posted October 10, 2008 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662179 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Author Share Posted October 10, 2008 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...... ?> Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662202 Share on other sites More sharing options...
Daniel0 Posted October 10, 2008 Share Posted October 10, 2008 Why are you talking to yourself? Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662208 Share on other sites More sharing options...
Maq Posted October 10, 2008 Share Posted October 10, 2008 Why are you talking to yourself? I just laughed out loud at work... thx Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662210 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Author Share Posted October 10, 2008 Becouse i keep finding diffrent examples drives me mad when a php function dosent work....... Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662211 Share on other sites More sharing options...
Daniel0 Posted October 10, 2008 Share Posted October 10, 2008 Uh... well... <?php session_start(); if (++$_SESSION['count'] > 20) { echo 'Sorry, no more views for you...'; } // other stuff ?> Quote Link to comment https://forums.phpfreaks.com/topic/127896-learning-sessions-properly/#findComment-662225 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.