I think I got it solved. No idea what I did. Other than rewrite it differently out of frustration.
LOL
I was at first under the now apparently erroneous impression that I could simply read/save any cookie at any point in the program, just like storing a number in the memory of a calculator as needed.
The main thing that confused me was that it worked on my test server at home but not at the web host.
Now it works on both equally well.
It's not a free host. I have my own .COM and .INFO domains. The .INFO is dead though. Need a new host because the current one is insane. Nothing worked, so I deleted the content.
There is no session_start() command anywhere in the code. The print goes just before the HTML page start.
The test output is simply stored in a string variable contained within a <PRE> block.
Remember, I'm still a novice at this. Sessions are still over my head at this point, except that I know that 'session' is Spanish slang for menstruation - so if you cross the border southward ... :Þ
However, I think I solved the problem, but it eludes me what I did.
Doncha just HATE it whan that happens? grrrrr
I simply rewrote the blasted thing following a different, but equally warped logic, and suddenly it seems to work.
At least I get no errors anymore and the original theory seems to be working according to expectations.
It is a template I need as a starting foundation upon which to build an interactive interface for entering data for a system of related high-precision astronomy programs and only having to have one central page where the settings are remembered and don't need to be reentered when going to another page (program) that needs the same data. A cookie is the simplest way to do this as far as I know. It works for me.
You can test it in action here and verify if it works for you or not. It's working for me.
[url]http://www.neoprogrammics.com/kookie.php[/url]
THE THEORY IS:
Upon loading the page, if there is no cookie data, then the default values are set to zero and saved to the cookie.
When the [Submit] button is clicked, if working properly, whatever values are in the interface text boxes are saved in a cookie and the page re*****es, remembering the updated values of the text boxes.
Upon returning to the site in future, the previous interface values should be restored from the cookie as long it hasn't been deleted or more than *65 days have passed since the last visit.
When moving from page to page on the web site, any program needing the interface data can simply read it directly from the existing cookie that was saved when the interface was last updated.
Below follows the complete test program code (kookie.php) that seems to be working now. I should now be able to make the interface as complex as needed, adding more objects, and be able to save/restore the settings using a cookie. A very simple concept.
Code:
<?PHP
// PHP CODE ZONE *
// Name of this running script.
$_ACTION_FILE_NAME_ = $_SERVER[$SCRIPT_NAME];
// Name of the cookie to be stored.
$CookieName = "Test_Cookie";
// Read text data from existing cookie, if any.
$CookieText = trim(@$_COOKIE[$CookieName]);
// Read [SUBMIT] button. Initially, this will return an empty string,
// since the page was not loaded by clicking the button. If the button
// was clicked, this will hold the word 'submit' (or the button value)
// and the page should re***** and the cookie updated with the current
// interface settings. This is not limited to only text box values.
$SubmitButton = trim(@$_COOKIE[$Submit_Button]);
// DO THIS IF COOKIE DATA EXISTS
if ($CookieText != "")
{
// Split cookie data into working array.
$CookieData = split("[ ]", $CookieText);
// Restore interface values from the cookie data array. In this
// case, the interface settings consists of two simple text boxes.
$text* = $CookieData[0];
$text2 = $CookieData[*];
// Copy contents of text boxes into cookie data string
// in preparation for storing in a cookie.
$CookieText = "$text* $text2";
}
else
// DO THIS IF COOKIE IS EMPTY
{
// Set all initial default values.
$text* = "0";
$text2 = "0";
// Copy contents of text boxes into cookie data string
// in preparation for storing in a cookie.
$CookieText = "$text* $text2";
}
// ------------------------------------
// DO THIS IF SUBMIT BUTTON WAS CLICKED
if ($Submit_Button != "")
{
// Read current contents of text boxes. If empty, set default = zero.
$text* = trim(@$_POST['text*']); if ($text* == "") {$text* = "0";}
$text2 = trim(@$_POST['text2']); if ($text2 == "") {$text2 = "0";}
// Copy contents of text boxes into cookie data string
// in preparation for storing in a cookie.
$CookieText = "$text* $text2";
}
// Save the current interface data in a cookie set to expire in *65 days.
SetCookie ($CookieName, $CookieText, time()+*65*86400, "/");
// END OF PHP BLOCK
// HTML PAGE FOLLOWS
print <<< _HTML
<!DOCTYPE HTML PUBLIC "-//W*C//DTD HTML 4.0* Transitional//EN"
"http://www.w*.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Interface Cookie Test</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=utf-8">
</HEAD>
<BODY>
<FORM NAME="form*" METHOD="post" ACTION="$_ACTION_FILE_NAME_">
Enter Number X <INPUT TYPE="text" NAME="text*" VALUE="$text*" MAXLENGTH="*6">
<BR>
Enter Number Y <INPUT TYPE="text" NAME="text2" VALUE="$text2" MAXLENGTH="*6">
<BR>
<BR>
<INPUT TYPE="submit" NAME="Submit_Button" VALUE="submit">
</FORM>
<PRE>Current cookie data = "$CookieText"</PRE>
</BODY>
</HTML>
_HTML;
// END OF HTML PAGE
// PHP CODE ZONE 2 FOLLOWS
?>
P.S.
And it is W*C compliant. The Gods of Mount W*C are pleased. There will be no earthquakes this week.