php poll page problem...
Posted: Mon Oct 13, 2014 5:57 pm
Hello:
I am trying to add a small poll to my page and I am having a slight problem with the setting of the cookie, or so I think that is my problem. My idea of this working would be to see if the cookie was set (person answered the poll) or not. If it was answered, display the ads.php page. If it was not set, then display the poll.php page. I really do have everything working except when I try to set the cookie, it says errors with headers already sent. Can someone please help me with this. Also, because it is not working just yet, after the poll is completed, I want the ads.php to be loaded. Here are the files I have...
index.php
poll.php
clean.php
I am trying to add a small poll to my page and I am having a slight problem with the setting of the cookie, or so I think that is my problem. My idea of this working would be to see if the cookie was set (person answered the poll) or not. If it was answered, display the ads.php page. If it was not set, then display the poll.php page. I really do have everything working except when I try to set the cookie, it says errors with headers already sent. Can someone please help me with this. Also, because it is not working just yet, after the poll is completed, I want the ads.php to be loaded. Here are the files I have...
index.php
Code: Select all
<?php
//
//
//
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Page</title>
<style>
body
{
margin: 0 auto;
max-width: 1280px;
font: normal 85%/150% arial,helvetica,sans-serif;
color: #CF6;
background: #777 url(../homepics/homeback.jpg) top center;
overflow-y: scroll;
}
#page_Body
{
float: left;
width: 100%;
}
#page_Left
{
float: left;
overflow: hidden; /* wrap floats and/or margins */
zoom: 1; /* trip has layout, wrap floats and/or margins legacy IE */
padding-right: 19.5em; /* #extras width + 0.5em space between */
}
.left_Body
{
padding: 5px;
margin-bottom: 0.5em;
background: #333;
border: 2px solid #444;
border-radius: 4px;
}
#page_Rite
{
float: left;
width: 19em;
margin-left: -19em;
}
.rite_Body
{
text-align: center;
color: #F44;
padding: 0.5em;
margin-bottom: 0.5em;
background: #333;
border: 2px solid #444;
border-radius: 4px;
}
</style>
</head>
<body>
<div id="page_Body">
<div id="page_Left">
<div class="left_Body">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget blandit turpis. Cras vel turpis non dolor lobortis mollis non eu mauris. Phasellus tincidunt tincidunt aliquam. Sed porttitor scelerisque blandit. Nam sed mi eget turpis rutrum blandit. Nullam ac commodo diam. Nunc interdum dui et ipsum posuere, at consequat elit fringilla. Etiam ultrices turpis eu purus placerat, non dictum urna fringilla. Aenean rutrum leo elit, elementum fringilla orci condimentum ut. Nam non mi sapien. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas vehicula eget nulla et facilisis. Suspendisse ultrices nec velit eget faucibus. Quisque nulla sapien, pellentesque sit amet tellus quis, egestas commodo velit.
</p>
</div><!-- end of .left_Body -->
</div><!-- end of #page_Left -->
</div><!-- end of #page_Body -->
<div id="page_Rite">
<div class="rite_Body">
<div id="page_Poll">
<?php
if(isset($_COOKIE["Voted"]))
{
//
// Yes, the vote happened.
echo "Hello, the ads page should be loaded.";
include 'ads.php';
//
}
else
{
//
// No, the vote never happened.
echo "Hello, the poll page should be loaded.";
include 'poll.php';
//
}
?>
</div><!-- end of #page_Poll -->
</div><!-- end of .rite_Body -->
</div><!-- end of #page_Rite -->
</body>
</html>
poll.php
Code: Select all
<?php
//
$errormsg = "";
//
if (isset($_POST['Submit']))
{
// YES, the Submit was clicked. Process as follows ...
include 'clean.php';
}
//
else
{
// NO, the Submit was not clicked. Do NOT Process ...
}
//
?>
<div id="form_container">
<h1><a>Poll/Survey</a></h1>
<form id="form_803001" class="appnitro" method="post" saction="poll.php">
Here is the very first Question 1 and needs an answer:<br>
<input type="radio" name="homepoll1" value="11">Answer 1-1<br>
<input type="radio" name="homepoll1" value="12">Answer 1-2<br>
<br>
<br>
Here is the next question 2 and this also needs an answer:<br>
<input type="radio" name="homepoll2" value="21">Answer 2-1<br>
<input type="radio" name="homepoll2" value="22">Answer 2-2<br>
<br>
<br>
<br>
<tr>
<td><font color="#FF0000"><b> <?php echo $errormsg;?></b></font></td>
</tr>
<br>
<br>
<br>
<input type="submit" Name="Submit" value="Submit">
<br>
<br>
<tr>
<td><font color="#FF0000"><b> <?php echo $errormsg;?></b></font></td>
</tr>
</form>
</div>
clean.php
Code: Select all
<?php
//
if (isset($_POST['Submit']))
{
// Question 1:
// Check if the field1 is answered.
if (isset($_POST['homepoll1']))
{
// Sanitize
$_POST['homepoll1'] = filter_var($_POST['homepoll1'], FILTER_SANITIZE_NUMBER_INT);
//
// Validate
$_POST['homepoll1'] = filter_var($_POST['homepoll1'], FILTER_VALIDATE_INT);
//
// Filter
if(($_POST['homepoll1'] > 10) && ($_POST['homepoll1'] < 13))
{
$poll_Math1 = "1";
}
else
{
// The information is NOT within the range of data ( Whitelisting ).
$errormsg = "Perhaps go somewhere.";
}
//
}
// The field1 is NOT answered.
else
{
$poll_Math1 = "0";
}
//
//
//
// Question 2:
// Check if the field2 is answered.
if (isset($_POST['homepoll2']))
{
// Sanitize
$_POST['homepoll2'] = filter_var($_POST['homepoll2'], FILTER_SANITIZE_NUMBER_INT);
//
// Validate
$_POST['homepoll2'] = filter_var($_POST['homepoll2'], FILTER_VALIDATE_INT);
//
// Filter
if(($_POST['homepoll2'] > 20) && ($_POST['homepoll2'] < 23))
{
$poll_Math2 = "1";
}
else
{
// The information is NOT within the range of data ( Whitelisting ).
$errormsg = "Perhaps go somewhere.";
}
//
}
// The field2 is NOT answered.
else
{
$poll_Math2 = "0";
}
//
$poll_Mathx = $poll_Math1.$poll_Math2;
//
//
switch ($poll_Mathx)
{
case 00:
$errormsg = "Please answer BOTH questions.";
break;
case 10:
$errormsg = "Please also answer the second question.";
break;
case 01:
$errormsg = "Please also answer the first question.";
break;
case 11:
// Real Escape
// Add the results to the database.
// setcookie("Voted", 'yes', time()+86400*300);
$errormsg = "Thank You.";
break;
default:
$errormsg = "Something went ballistic.";
}
//
}
else
{
// $msgpoll = "SUBMIT has NOT been clicked.";
}
//
?>