Stored Sessions Data Not Found
Happy New Years, Folks,
My first 2014 puzzlement (may they be few): I'm attempting to use sessions. My efforts produce error messages. I am hoping someone here can explain what I am doing wrong.
The visitor is presented with a menu that consists of pages s/he can read. One of the menu items is q0.php. In q0.php I define $_SESSION["code"]. Then q0.php causes quotations.txt to load:
Code:
<?php
$_SESSION["code"] = "0";
header( 'Location: page.php?here=quotations' );
?>
Note: I have no session_start(); statements because I set session.auto_start to "1" in my php.ini file.
Here is quotations.txt (a grossly abbreviated excerpt), where I attempt to use $_SESSION["code"], defined above in q0.php:
Code:
<?php
$lastUpdate = date( "j F Y", filemtime( "pageContent/quotations.txt" ) );
$quotations = array(
"We, as criminal defense lawyers, are forced to deal with <a href='http://en.wikipedia.org/wiki/Torture_memos' target='_blank'>some of the lowest people on earth</a>. People who have no sense of right and wrong. People who will lie in court to get what they want. People who do not care who gets hurt in the process. It is our job, our sworn duty as criminal defense lawyers, to protect our clients from those people.",
"Cynthia Rosenberry",
"For to him that is joined to all the living there is hope: for a living dog is better than a dead lion.
<br />
<br />
For the living know that they shall die: but the dead know not anything, neither have they any more a reward; for the memory of them is forgotten.
<br />
<br />
Also their love, and their hatred, and their envy, is not perished; neither have they any more a portion for ever in any thing that is done under the sun.",
"Ecclesiastes 8:4-6",
);
if ( $_SESSION["code"] == "0"
|| $_SESSION["code"] == "1") {
$bigIndex = rand(0, (count($quotations) -1)) & 65534; // select entry, force even
$_SESSION["quoteIndex"] = $bigIndex;
}
else {
$bigIndex = $_SESSION["quoteIndex"];
}
echo "<br /><br /><div class='bigquote'> {$quotations [$bigIndex]} <br /><br /><div align='right'>"; // display
$noSource = " "; // To test whether we need, or can skip, Part Two
if ($quotations [$bigIndex + 1] != $noSource) { // ...then we have an attribution to display for Part Two,
echo $quotations [$bigIndex + 1] . "<br /><br />"; // so display it already
}
if ( $_SESSION["code"] == "0"
|| $_SESSION["code"] == "2") {
$universe = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0"; // establish Part Three (partial) universe
$characters = explode(" ", $universe); // make array of it
shuffle ($characters); // go to Buffalo
$characters = array_slice($characters, 20, 3); // trim. The "20" is somewhat arbitrary
$decorations = array( // "Mommy, see all the pretty decorations."
"♠",
"<span style='color : #ff4040; '>♥</span>",
"<span style='color : #ff4040; '>♦</span>",
"∫",
"ω",
"π",
"∑",
"♣"
);
shuffle ($decorations); // to Buffalo, too, the decorations
$decorations = array_slice($decorations, 0, 3); // pare decorations
$decorations = array_merge($decorations, $characters); // meld tree onto decorations
shuffle ($decorations); // again to Buffalo we go, to complete Part Three
$_SESSION["decorations"] = $decorations;
}
else {
$decorations = $_SESSION["decorations"];
}
echo "Your Access Code is " . implode(" ", $decorations) . ".<br /><font size='-2'>Access code broken? Click <a href='http://www.MarainLaw.com/quotations'>*** here ***</a> to replace it.</font><br /><br /><br /></div></div>";?>
Here are the generated error messages (technically, I suppose, "Notices"):
Notice: Undefined index: code in /var/www/html/pageContent/quotations.txt on line 2956
Notice: Undefined index: code in /var/www/html/pageContent/quotations.txt on line 2957
[Echo'd Quotation, followed by Attribution]
Notice: Undefined index: code in /var/www/html/pageContent/quotations.txt on line 2984
Notice: Undefined index: code in /var/www/html/pageContent/quotations.txt on line 2985
Your Access Code is π j G ♦ ♠ z.
Access code broken? Click *** here *** to replace it.
quotations.txt is a very large file that, as I indicated above, I've heavily excerpted. A version that works is at http://www.marainlaw.com/page.php?here=quotations.
A.