Sessions are easier to handle and will only last until the user closes the browser = Instant logout / session deletion, however a mixture is good![]()

Sessions are easier to handle and will only last until the user closes the browser = Instant logout / session deletion, however a mixture is good![]()
Was Danny's idea orig
And i might make a new version but the admin chooses whether to use sessions or cookies?
Coming and going...
Highers are getting the better of me
Just as a quick rewrite, it would probably be more secure to use sessions for something like this, plus the code can be optimised quite easily.
For example, this (if java hasn't completely overridden my php ability) should do pretty much the same with less bloat & better readabilty.
-include at top of pagesPHP Code:<?php
session_start(); // start sessions
//Change these
$noDisplayMessage =" no site ere ";
$timesNeeded = 3; //how many refreshes are needed to view page
//Don't Change
if($_SESSION['views']<$timesNeeded) //PHP will initialise at zero.
{
$_SESSION['views']++; //increment sessions counter
die($noDisplayMessage); //die and show message
}
?>
A possible further optimisation would be to put the code in another file, then u can just include it when ever you need it. Only issue is with sessions as it may conflict if its initialised a second time in the main code... a simple edit would fix that though.
Last edited by Mentor; 14-12-2007 at 05:53 AM.
Omg awesome script. Good work.
This is the one I use to hide sites from teachers at school, own code:
PHP Code:<?php
ob_start();
$no = "Nothing here.";
$yes = "You're well smart.";
if(!$_COOKIE['views']){
setcookie("views","1");
die($no);
}elseif($_COOKIE['views'] == "1"){
setcookie("views","2");
die($no);
}elseif($_COOKIE['views'] == "2"){
setcookie("views","3");
die($no);
}elseif($_COOKIE['views'] == "3"){
die($yes);
}
?>
Last edited by lolwut; 14-12-2007 at 10:55 PM.
i've been here for over 8 years and i don't know why
Again, lots of wasted code, you only need one check, not 4 :rolleyes:This is the one I use to hide sites from teachers at school, own code:
PHP Code:<?php
ob_start();
$no = "Nothing here.";
$yes = "You're well smart.";
if(!$_COOKIE['views']){
setcookie("views","1");
die($no);
}elseif($_COOKIE['views'] == "1"){
setcookie("views","2");
die($no);
}elseif($_COOKIE['views'] == "2"){
setcookie("views","3");
die($no);
}elseif($_COOKIE['views'] == "3"){
die($yes);
}
?>
(or 2 if you want the pre final code message to appear o.0)
The greater than / less than comparisons <> are there for a reason.
<?php
ob_start();
$no = "Nothing here.";
$yes = "You're well smart.";
if($_COOKIE['views'] == "3"){
echo("$yes");
}else{
setcookie("views", ++);
die($no);
}
?>
Last edited by DeejayMachoo$; 15-12-2007 at 01:18 PM.
A few logical + syntactical errors there.
++ requires a variable to add to.
Secondly, if we assume the cookie set was actually storeing an incriment counted, it would only ever display yes and the final page on the 3rd viewing, then never again after that till the cookie was deleited or expired? Which could be a pain in the ****
Again, why the hell are you using cookies.
Sessions are better, plus they are there for the browser session, cookies are there.. until.. a while.
Want to hide these adverts? Register an account for free!