Sessions are easier to handle and will only last until the user closes the browser = Instant logout / session deletion, however a mixture is good :)
Printable View
Sessions are easier to handle and will only last until the user closes the browser = Instant logout / session deletion, however a mixture is good :)
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.
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);
}
?>
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.