Warnings and errors are on for the localhost server. I don't know about the live server. But clearly I'm setting the two cookies in the body:
PHP Code:
<?php
header('Content-type: text/html; charset=utf-8');
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Quote Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="quote.css" type="text/css">
<!--
// Quote Fetching Script (c)2012 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/
// username: jscheuer1 - This Notice Must Remain for Legal Use
-->
</head>
<body>
<div class=quotecontent>
<div class="quotecontainer">
<?php
if(isset($_GET['clear'])){
setcookie('quoteIndexes', "", time() - 3600);
setcookie('bigIndexRand', "", time() - 3600);
}
$qpattern = '/[^a-z]+$/i';
$quotefile = 'quotations_num.php';
$quoterights = false;
$lastUpdate = date( "j F Y", filemtime($quotefile));
include $quotefile;
$noAuthor = " ";
$theCount = count($quotations);
$numQuotes = $theCount / 2;
$maxlength = strlen($numQuotes);
$hqnum = isset($_GET['hqnum'])? abs($_GET['hqnum']) : '';
if($hqnum and is_nan($hqnum)){
$hqnum = '';
}
$bigIndexRand = isset($_COOKIE['bigIndexRand'])? explode('.', $_COOKIE['bigIndexRand']) : array();
if(isset($_GET['qnum'])){
$bigIndex = ($_GET['qnum'] + 2) % $theCount & ~1;
} elseif ($hqnum){
$bigIndex = (($hqnum -1) * 2) % $theCount & ~1;
} elseif (isset($_GET['pnum'])){
$bigIndex = ($_GET['pnum'] - 2 + $theCount) % $theCount & ~1;
} else {
$bigIndex = mt_rand(0, $theCount - 1) & ~1;
if(!isset($_GET['clear']) and isset($_COOKIE['bigIndexRand'])){
setcookie('bigIndexRand', $_COOKIE['bigIndexRand'] . ".$bigIndex", time() + 3600 * 24 * 365);
} else {
setcookie('bigIndexRand', $bigIndex, time() + 3600 * 24 * 365);
}
$bigIndexRand[] = $bigIndex;
}
if(!isset($_GET['clear']) and isset($_COOKIE['quoteIndexes'])){
$quoteIndexes = $_COOKIE['quoteIndexes'] . '.' . ($bigIndex / 2 + 1);
$quoteIndexes = explode('.', $quoteIndexes);
} else {
$quoteIndexes = $bigIndex / 2 + 1;
$quoteIndexes = array($quoteIndexes);
}
echo ($bigIndex / 2 + 1) . ' of ' . $numQuotes;
?>
<br /><br /><div class="quotations">
<?php
echo $quotations [$bigIndex];
?>
<br /><br /><div class="byline">
<?php
if ($quotations [$bigIndex + 1] != $noAuthor) {
echo "- {$quotations [$bigIndex + 1]}<br /><br />";
}
?>
</div></div>
<div class="clear">Quote File dated: <?php echo $lastUpdate; ?></div>
<div class="center">
<a href="<?php echo "{$_SERVER['PHP_SELF']}?pnum=$bigIndex" ; ?>" title="Previous in Numeric Order">Prev Quote</a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>" title="Get a Random Quote">Random Quote</a>
<a href="<?php echo "{$_SERVER['PHP_SELF']}?qnum=$bigIndex" ; ?>" title="Next in Numeric Order">Next Quote</a>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
Go To #: <input type="text" name="hqnum" maxlength=<?php echo $maxlength; ?> size=<?php echo $maxlength + 1; ?> title="Input Number from 1 to <?php echo $numQuotes; ?>" />
</form>
<div class="clear"></div>
<div><b>History</b>:<span class="center">
<a href="<?php echo "{$_SERVER['PHP_SELF']}?clear=clear" ; ?>" title="Clear History, Reload with a Random Quote">
Clear</a></span>
<div id="history"><?php
$quoteIndexes = array_unique(array_reverse($quoteIndexes));
function formatval($v){
$v = trim($v);// . '';
$v = str_pad($v, 3, ' ', STR_PAD_LEFT);
return $v;
}
foreach ($quoteIndexes as $val){
$bval = ($val - 1) * 2;
$asterisk = in_array($bval, $bigIndexRand)? '<span class="asterisk">*</span>' : '<span class="asteriskhidden">*</span>';
echo "<a href='{$_SERVER['PHP_SELF']}?hqnum=$val'><pre>" .
formatval($val) . "</pre></a> - $asterisk" .
preg_replace($qpattern, '', substr(strip_tags(html_entity_decode($quotations [$bval], ENT_QUOTES, 'UTF-8')), 0, 20)) .
" . . .<br/>\n";
}
setcookie('quoteIndexes', implode('.', array_reverse($quoteIndexes)), time() + 3600 * 24 * 365);
?></div><pre> </pre> <span class="asteriskhidden">-</span>
<span class="asterisk">*</span><span class="smaller">a quote chosen at random at some point</span></div>
</div>
</div>
<?php if($quoterights){echo "<div class='quoterights'>$quoterights</div>";}; ?>
<!-- The below HTML and PHP may be used (be careful, backup what you've got) to generate -->
<!-- a renumbered/reformated version of the quotes section of the quotes file -->
<!-- <textarea name="" cols="50" rows="5" wrap="off"> --><?php
/* foreach ($quotations as $key => $val){
echo ($key % 2 == 0)? "\n//#" . ($key / 2 + 1) . "\n" : '';
echo '"' . str_replace('"', '\"', $val) . "\",\n";
} */
?><!-- </textarea> -->
<!-- End Optional Renumbering/Reformatting Routine -->
<?php
//to see what the cookies are doing, uncomment the below line:
//print_r($_COOKIE);
?>
</body>
</html>
Note: The first two are for clearing the cookies if that link is clicked. The other three (even farther down in the code) are for setting the cookies. All five are in the body of the page.
Bookmarks