Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   How to test if cookies are being accepted? (http://www.greenguysboard.com/board/showthread.php?t=15956)

Cleo 2005-01-31 12:35 PM

How to test if cookies are being accepted?
 
I have a little php page that tests if they are behind a firewall and I need it to also see if they have cookies enabled.

cd34 2005-01-31 12:41 PM

without doing a redirect after setting a cookie, I don't know of a reliable way to do so.

Basically something like:
index.php

setcookie ('cookied','yes')
header('Location: cookietest.php');
?>

cookietest.php
if ($_COOKIE['cookied']) {
print "I've got your warm gooey chocolate chip cookie right here";
}
?>

There are other methods, this one is pretty much tried and true. That is consquently the behavior that got one of my web sites banned from google for two years :)

There might be errors in the code, I didn't test it, but, it should be pretty darn close.

Cleo 2005-01-31 12:51 PM

A redirect would be fine but I can't figure out where I should put that first bit of code.

This is the page I'm using
http://cleoslinks.com/info.php

swedguy 2005-01-31 01:20 PM

The one cd34 posted works great, if you dont' mind redirecting pages. I have one piece of code that does the testing through an image instead

On index.php there's an image called image.php

image.php sets a cookie and redirects to image2.php.
image2.php checks if the cookie exist, if not then you have a non-cookie and you can do whatever you want with it.

I'll see if I can find the code.

cd34 2005-01-31 01:33 PM

; on the setcookie line :)

swedguy 2005-01-31 01:42 PM

I couldn't find it but I made a quick one: http://nuvisiongroup.com/test/cookietest.html

you should get a green image if you have cookies turned on, red if you don't.

http://nuvisiongroup.com/test/cookietest.txt - source for the html page
http://nuvisiongroup.com/test/image.phps - source for image.php

Doing it that way doesn't fit everybody. But it's a good way to do stealth cookie testing.

Cleo 2005-01-31 02:10 PM

Yours works perfect

Mine naturally doesn't

Cleo 2005-01-31 03:00 PM

|banghead|

I really need to try to learn php…

I have a page with the image tag calling up image.php but it is just showing a broken image.
http://cleoslinks.com/info.php

I notice that I can load your image.php in a browser but if I load mine I get an error on line 10
http://cleoslinks.com/image.php

This is what I have in that file
http://cleoslinks.com/image.txt

|banghead|

cd34 2005-01-31 03:03 PM

I don't think your server has php4-gd installed

Cleo 2005-01-31 03:15 PM

PHP Version 4.3.10

Configure Command './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-exif' '--with-gd=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-zlib' '--with-ttf=/usr/local' '--with-freetype-dir=/usr/local' '--enable-gd-native-ttf' '--with-mysql=/usr/local/mysql' '--with-curl' '--with-ncurses' '--enable-cli' '--enable-safe-mode' '--enable-shared' '--enable-static' '--enable-ftp' '--with-mcrypt' '--enable-calendar' '--with-xls' '--with-soap'

swedguy 2005-01-31 03:19 PM

Odd that you're getting an error on that line. Sounds like a missing ;.... but there is no missing ;

You can replace the image part with this instead (if you don't have gd installed)

PHP Code:

header("Content-type: image/gif");
printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%"71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59); 

It's a 1x1 transparent gif.

swedguy 2005-01-31 03:27 PM

http://nuvisiongroup.com/test/image2.phps

That's what your image.php should look like, once we get the error on line 10 taken care of. Are you 100% sure that image.php and image.txt are exactly the same? (have to ask :))

cd34 2005-01-31 03:40 PM

check

phpinfo();
?>

does it make any mention of gd?

The compile options look right. Perhaps the php.ini file is missing

extension=gd.so

Cleo 2005-01-31 03:41 PM

I got it
http://cleoslinks.com/info.php

I turned on invisibles in my editor and realized that I was picking up tabs when I copied and pasted.

Cleo 2005-01-31 03:44 PM

BTW I'm using this page for the ever annoying members of Angel's site for when they send me mail asking me why they are having trouble viewing the feeds or something.

Thanks cd34 and swedguy for the help. :)

swedguy 2005-01-31 03:49 PM

No problem :)


All times are GMT -4. The time now is 01:56 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc