Ok, i have two pages. One page pollsgirls.php which has html and one bit of php coding....
<?php
if(isset($_COOKIE['thename'])) {
$myName = ($_COOKIE['thename']);
echo("Wow! Actually, Looks like you've already voted! We'll send you straight to the pollz now!");
echo("<form name=\"form1\" method=\"post\" action=\"polls.php\">");
echo(" <p>Your Name is = $myName ");
echo(" <input name=\"myName\" type=\"hidden\" id=\"myName\" value=\"$myName\"><br>");
echo(" <input name=\"myVote\" type=\"hidden\" id=\"myVote\" value=\"girls\">");
echo(" <input name=\"myCo\" type=\"hidden\" id=\"myCo\" value=\"yes\">");
echo(" <input type=\"submit\" name=\"Submit\" value=\"Lets Go then... Click here! \">");
echo(" </p>");
echo(" </form>");
} else {
echo("<form name=\"form1\" method=\"post\" action=\"polls.php\">");
echo(" <p>Your Name = ");
echo(" <input name=\"myName\" type=\"text\" id=\"myName\"><br>");
echo(" <input name=\"myVote\" type=\"hidden\" id=\"myVote\" value=\"girls\">");
echo(" <input name=\"myCo\" type=\"hidden\" id=\"myCo\" value=\"no\">");
echo(" <input type=\"submit\" name=\"Submit\" value=\"Submit\">");
echo(" </p>");
echo(" </form>");
}
?>
So if the cookie exists it hides the form feild called myName and fills the value in with the name in the cookie... This is the polls.php which deals with what is POSTED to it. Heres the code
<?php
$name = $_POST['myName'];;
$tovote = $_POST['myVote'];;
$iscookie = $_POST['myCo'];;
$ip = getenv('REMOTE_ADDR');
$today = gmdate("F j, Y, g:i:s a");
$file = file_get_contents("pollz.txt");
$pollsave = ("$file $name with $ip. Went To $tovote on $today. Had Cookie $iscookie NEXT ");
if ($iscookie == "yes") {
if ($name == "") {
echo("Please Go back and Fill in a Name");
} else {
$fpkk = fopen("pollz.txt", "w");
if(fwrite($fpkk, $pollsave)) ;
fclose($fpkk);
if ($tovote == "boys") {
$url = ("http://www.mickyg.co.uk/subsite/pollboys1.htm");
} else {
$url = ("http://www.mickyg.co.uk/subsite/pollgirls1.htm");
}
header("Location: $url");
echo ("Redirecting... Please Wait...");
}
} else {
if ($name == "") {
echo("Please Go back and Fill in a Name");
} else {
setcookie("thename", $name, time() - 3600*24*30);
$fpkk = fopen("pollz.txt", "w");
if(fwrite($fpkk, $pollsave)) ;
fclose($fpkk);
if ($tovote == "boys") {
$url = ("http://www.mickyg.co.uk/subsite/pollboys1.htm");
} else {
$url = ("http://www.mickyg.co.uk/subsite/pollgirls1.htm");
}
header("Location: $url");
echo ("Redirecting... Please Wait...");
}
}
?>
I think the problem is When it tries to set the cookie.😕 But im not 100% sure. Can anyone give me some hints and tips please.
Thanks