Well cookies have got to be one of the easiest things to program in php, all you have to do is send one simple little command at the begining of your php script. A little warning, it has to be sent before any, and I mean any, echo/prinf or any other display code else it'll fail with some sort of error message such as "Header has already been sent by sompage.php".
Function:
int setcookie (string name, string value, int expire, string path, string
domain, int secure)
Examples:
1. setcookie ("TestCookie", "Test Value");
2. setcookie ("TestCookie", $value,time()+3600); / expire in 1 hour /
3. setcookie ("TestCookie", $value,time()+3600, "/~rasmus/", ".utoronto.ca", 1);
The value can be accessed in two dieferent ways, it all depends on your servers settings and you personal preferences:
$TestCookie;
$HTTP_COOKIE_VARS["TestCookie"];
So for your little script it would be something like this:
if(isset($Pageviewed))
{
header ("Location: http://somesite.com/somepage.php"); //Redirect to other page
exit; //Exit so more code doesn't execute.
}
setcookie ("PageViewed", "TRUE");
//show page code goes here.
Oh one thing to note thou, I'm not sure if you want the user to only see the page once per visit or once and only once forever, if it's forever then you'll need to use the timestamped values in the setcookie function.
I won't take too much credit for this code, most of it is just a copy/paste job from the php manual.