Page 1 of 1

Cookie problems

Posted: Wed Oct 09, 2002 5:11 am
by sclozza
I have a small HTML form that is used for searching. This sends the inputted data to a PHP script, using POST (Dont know if that is relevant).

What I want it to do is to record the string that I sent to search, and when someone goes to the search page again, it displays their last entered search.

I have got the script creating a cookie fine, but I am having troubles reading it back.

I am using:

Code: Select all

<? 
$search = $_POST&#1111;"searchEntry"];
setcookie("previousSearch", $search, time()+36000, "/30055351/"); 
?>
to create the cookie (The 30055351 is a statically unique number to me). searchEntry is the field from the form. It is before the <html> tags :P

Then in the html page, with the form I have

Code: Select all

<?
if (isset ($previousSearch)) &#123;
echo "<p>" . $previousSearch . ": Your last search</p>"; 
&#125; 

else &#123;
echo "<p>Welcome to this page for the first time.</p>"; 
&#125;
?>
I am probably over looking something very obvious, but I just cant seem to get it to work.

I am using IE6, with Xitami (Windows, here) and Apache(Solaris, remote server).

Thanks for any help

Posted: Wed Oct 09, 2002 5:19 am
by twigletmac
Try accessing the cookie as $_COOKIE['previousSearch'] rather than as $previousSearch.

Mac

Posted: Wed Oct 09, 2002 5:42 am
by sclozza
Thank you for your prompt reply!

I changed it to $_COOKIE and it still isnt returning.

Would these 2 factors influence it:

a) The script is in ../scripts/search.php and the form is in ../html/search.html, does the 2 in different directories matter?

b) Does the positioning in the HTML document matter? I know for the php script it is vital before the <html> tags, I currently have it after the submit and reset buttons, near to the bottom of the page.

Thanks.

Posted: Wed Oct 09, 2002 3:48 pm
by JPlush76
yep, cookies will only read a cookie from the same root directory

so if you set a cookie on one dir, you have to read it in that same dir

someone here might know a way around that however