473,243 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,243 software developers and data experts.

Check for cookies

TG
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?
Jul 17 '05 #1
5 3154
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?

Jul 17 '05 #2
You can use JavaScript to tell whether there's a cookie or not in the first
page:

<script>

while(document.cookie == null || document.cookie.length == 0) {
alert('You must enable cookie!');
}

</script>

If the page starts a session, then there should be one.

Uzytkownik "TG" <tg********@cox.net> napisal w wiadomosci
news:TDAZb.13810$Dc2.8427@lakeread01...
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?

Jul 17 '05 #3
TG
Thanks!

That worked perfectly.

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:8L********************@comcast.com...
You can use JavaScript to tell whether there's a cookie or not in the first page:

<script>

while(document.cookie == null || document.cookie.length == 0) {
alert('You must enable cookie!');
}

</script>

If the page starts a session, then there should be one.

Uzytkownik "TG" <tg********@cox.net> napisal w wiadomosci
news:TDAZb.13810$Dc2.8427@lakeread01...
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?


Jul 17 '05 #4
"TG" <tg********@cox.net> wrote in message news:<TDAZb.13810$Dc2.8427@lakeread01>...
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?


Manual & usernotes are your friends <http://in2.php.net/setcookie>

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<8L********************@comcast.com>...
You can use JavaScript to tell whether there's a cookie or not in the first
page:

<script>

while(document.cookie == null || document.cookie.length == 0) {
alert('You must enable cookie!');
}

</script>

If the page starts a session, then there should be one.


Why? How? :-/

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
7
by: | last post by:
It is possible to check via ASP whether cookies are enabled for a person's web browser and based on this check send him to another page which does not support cookies (ie login?)? Thanks Jason
11
by: Jennifer | last post by:
Is there a way to check for to see if the user has session cookies enabled? I know how to check to see if they have cookies in general enabled, but how do you test for just session cookies? ...
1
by: rsindall | last post by:
Hi I have some code for checking for cookies that sets on page1 and checks on page2. and its based on the code my MS ...
0
by: Steve Johnson | last post by:
I've set IE 6.0 (in Windows XP) to block all cookies, yet Response.Browser.Cookies. still returns True. Additionally, attempts to write cookies are successful. Here's a code snippet. Does...
4
by: mike parr | last post by:
I'm trying to do a check to see if the client browser has cookies enabled. But my code below always gives me the value for acceptsCookies = true, whether the machine has cookies enabled or not. ...
1
by: Bobby Edward | last post by:
How do I check to see if a cookie exists or not? I tried these 3 but they don't work... If Not Request.Cookies("UserSettings")("IsAdmin") Is Nothing Then... If...
3
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
4
by: David C | last post by:
Is there a way to check to see if the browser accepts cookies? I have the following line of code that is giving an error "Object reference not set to an instance of an object." with the following...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.