TG wrote:
This is more of a pain than I thought it would be. I need a simple code
segment to determine whether a browser accepts cookies or not. When I pass
variables between pages when cookies are turned off, the global variables
are empty between pages, fine, that tells me cookies store the global
variables - right? I store the values in $_session and when cookies are
turned on values are passed between web pages - I can see these values in
fields that are displayed in the next web page.
I need to be able to check on the 'first' entry webpage after a user enters
that page directly whether or not their browser accepts cookies at that
point. Everything I have tried complex to simiple won't work. How do I do
this?
You could use PHP or JavaScript but unfortunately because of different
issues with different browsers there is no method to tell you straight
off the bat if cookies are enabled or disabled... Each browser has to
provide something in its header (see phpinfo(); output help page and
test it with your browser).
But... Perhaps I am misunderstanding you, but are you saying that your
cookies do not appear until you use sessions?
Cookies and sessions are not related - They can provide similar
functionality, but you do not need one to have the other.
Cookies I believe work by createing values, either in a small temporary
file or in memory (pending if they have an expiry time or not).
Sessions I believe work by extending your URL in the address bar with
something cryptic that will correspond to a temporary file held on the
server. I believe sessions should work across all browsers, or at least
more so than cookie based transactions.
Your cookie is only visable with a browser refresh thus the cookie you
might have set earlier (before you started to use sessions) has probably
become visable to you after a browser refresh - It has nothing to do
with any sessions being switched used, or not.
Try the following simple test:
<?
if(count($_COOKIE)>0)
{ print("Our cookies are set<br>");
foreach($_COOKIE as $cookieName=>$cookieValue)
{ print("<br>$cookieName = $cookieValue");
}
}
$random=mt_rand();
set_cookie("random","$random");
print("<br>Current random = $random");
print("<br>Last random = $_COOKIE[random]");
?>
Using the above code, the loop and message "Our cookies are set" should
be displayed at the second refresh of your browser.
Also, the Current random should always differ "Last random" value.
If you want to use cookies, and you want to check that the cookie you
set, then have your first page set a cookie value from the onset of its
display - You could force a browser refresh or re-direct to another page
and then check if your cookie is available or not... its a solution, but
not an environmentally friendly one...
Does that help you in any way?