
Sorry, wasn't aimed at youI saw it the other day.
I just seem him contining to post using cookies![]()
Not really, it kinda depends on what your trying to do, remembering a users login details for instance is a task cookies easily > sessions for instance.
Both are better at different things, the skill is to use the right one for the right purposes![]()
Is there a way of having it like danny had a 'panic button' where if you clicked/ refreshed the page it will show the not available message , and if you refreshed again it will show the site contents?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.
I'm guessing it can be done by having it so on the 3rd refresh it changes it back to 1 refresh and it keeps going in a loop?
or have a special condition added.Is there a way of having it like danny had a 'panic button' where if you clicked/ refreshed the page it will show the not available message , and if you refreshed again it will show the site contents?
I'm guessing it can be done by having it so on the 3rd refresh it changes it back to 1 refresh and it keeps going in a loop?
Say on the page theres a link called panic.
The link points to whateverpagethisison.php?a=panic
Now with this code that would reset the refresh counters and load the first page
(bin doin Java to long, cant remember if phps else if is joint or not. if im wrong add a space in there 2 fix)PHP 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($GET_['a']=="panic") // if panic button hit
{
$_SESSION['views'] = -1; // set views counter to zero
header("Location: ".$_SERVER['PHP_SELF']) ; // reload page
}
elseif($_SESSION['views']<$timesNeeded) //PHP will initialise at zero.
{
$_SESSION['views']++; //increment sessions counter
die($noDisplayMessage); //die and show message
}
?>
Its joint.or have a special condition added.
Say on the page theres a link called panic.
The link points to whateverpagethisison.php?a=panic
Now with this code that would reset the refresh counters and load the first page
(bin doin Java to long, cant remember if phps else if is joint or not. if im wrong add a space in there 2 fix)PHP 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($GET_['a']=="panic") // if panic button hit
{
$_SESSION['views'] = -1; // set views counter to zero
header("Location: ".$_SERVER['PHP_SELF']) ; // reload page
}
elseif($_SESSION['views']<$timesNeeded) //PHP will initialise at zero.
{
$_SESSION['views']++; //increment sessions counter
die($noDisplayMessage); //die and show message
}
?>
Want to hide these adverts? Register an account for free!