There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash dns driver drivers error ethernet excel freeze gaming google hard drive hardware hdmi internet laptop mac malware memory monitor motherboard mouse network printer problem ram registry router server slow software sound svchost.exe trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: PHP and Cookies

Reply  
Thread Tools
pcpro17's Avatar
Computer Specs
Member with 441 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Intermediate
26-Jun-2009, 12:08 AM #1
Exclamation Solved: PHP and Cookies
Hello. I'm having trouble retrieving cookie data with PHP. I can set the cook okay with setcookie( ... ). When I set a cookie, it's like this:

PHP Code:
setcookie"user_first_name"$_SESSION['user_first_name'], (time() + 60*60*24*$cookie_expiry_time_in_days
I know the cookie sets because I can view its contents in my browser's cookie manager.

Does anyone know how you're suppose to retrieve the cookie with PHP? I tried variants of both this
PHP Code:
$foo $_COOKIE['user_first_name']; 
and this
PHP Code:
$foo unserialize($_COOKIE['user_first_name']); 
without results.

Any thoughts or suggestions would be greatly appreciated. Thanks.
omuyelijah's Avatar
Computer Specs
Member with 119 posts.
 
Join Date: Jan 2006
Location: Nigeria
Experience: Intermediate
26-Jun-2009, 09:51 AM #2
Hi Pcpro17,

I've worked with PHP a long time and this is how I get cookies work:

//set cookie
setcookie("cookieName","cookieValue");

//display cookie
echo $_COOKIE['cookieName'];

//pass into another variable
$var=$_COOKIE['cookieName'];

This should work for you.
pcpro17's Avatar
Computer Specs
Member with 441 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Intermediate
26-Jun-2009, 10:54 AM #3
Thanks, omuy. I've tried that, but to no avail. Is there perhaps a setting that needs to be checked in the PHP configuration file?
MRdNk's Avatar
Computer Specs
Member with 439 posts.
 
Join Date: Apr 2007
Location: UK
Experience: Damn I'm good!
27-Jun-2009, 09:21 AM #4
Does your browser have cookies on?
pcpro17's Avatar
Computer Specs
Member with 441 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Intermediate
27-Jun-2009, 12:33 PM #5
Yes, the cookie sets without any problems. I've verified this problem with Firefox, IE, and Opera.
nj2b's Avatar
Member with 57 posts.
 
Join Date: Sep 2006
27-Jun-2009, 07:57 PM #6
When you check them, do you check to see if they have an expire date and not simply for the current session? Try either print_r($_COOKIE) or vardump($_COOKIE); and see if you get any output.

What is the var type of $cookie_expiry_time_in_days? You might try casting that to ensure it's an integer (int)$cookie_expiry_time_in_days as php may be casting it to a type that results in 0, which would make a session cookie.
pcpro17's Avatar
Computer Specs
Member with 441 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Intermediate
30-Jun-2009, 07:57 PM #7
Thanks for the suggestions! Though the problem is not yet solved, they did yield some more clues:

print_r( $_COOKIE ) yields

Quote:
Array ( [PHPSESSID] => dg4kmotfsnq40gi4rmigba6gc1 )
var_dump( $_COOKIE ) yields

Quote:
array(1) { ["PHPSESSID"]=> string(26) "dg4kmotfsnq40gi4rmigba6gc1" }
var_dump( $cookie_expiry_time_in_days ) yields

Quote:
int(14)
Also, attached is a screen capture of the user_first_name cookie that is set in my browser.

Thanks again!
Attached Thumbnails
Solved: PHP and Cookies-cookies.jpg  
pcpro17's Avatar
Computer Specs
Member with 441 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Intermediate
02-Jul-2009, 06:12 PM #8
Okay, I think I've got it solved, now. It seems that there were a number of issues conspiring. The big ones:

$cookie_expiry_time_in_days is a global variable, and I was trying to use inside a function. This problem was solved by adding the global tag.

The other problem was that the path in the cookies was defaulting to /uif/ the server folder from which setcookie was being called. This problem was solved by forcing the path to "/" in the calls to setcookie.

Thank you everyone for your help!
silverado4's Avatar
Senior Member with 897 posts.
 
Join Date: Nov 2004
Experience: Advanced
06-Jul-2009, 05:57 PM #9
Method Post not allowed
omuyelijah

You said you worked with PHP a long time,
I am using website x5 revolution 8,
When I create their e-mail form on my "comment" page,
It works ok in the software, but when I upload it to my web space,
and click on "send"
I get the following:
Method not allowed
The requested method POST is not allowed for the URL / myname/test/files/mail_p_003_8_00.php

I talked to my support that owns the software, they said that the PHP must be enabled by the ISP provider.

I talked to my ISP provide "wideopenwest.com" and they said they never enable or activate anything.

I'm in the middle, I can not get an answer from anyone on what to do.
Here is my site, try the comment page

Thanks I hope you can help me,
Make it easy, I don't know HTML that much.
pcpro17's Avatar
Computer Specs
Member with 441 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Intermediate
06-Jul-2009, 06:07 PM #10
It sounds like they're a very hands-off hosting service. You'll probably need to install PHP yourself, if you want to use it.

http://www.php.net/downloads.php

Personally, I use DreamHost, which is relatively inexpensive, and they have lots of pre-installed/easy-to-configure goodies for no extra cost. I highly recommend them for any new web-developer.
silverado4's Avatar
Senior Member with 897 posts.
 
Join Date: Nov 2004
Experience: Advanced
06-Jul-2009, 06:37 PM #11
Which File?
There were so many files at that PHP site, I don't know what to download and how to use it.
silverado4's Avatar
Senior Member with 897 posts.
 
Join Date: Nov 2004
Experience: Advanced
07-Jul-2009, 02:12 PM #12
From My ISP Provider
The below is from my ISP provider, looks like I can't use PHP
Do you know where I can get an HTML that does the same to create
an e-mail form?
Thanks
Silverado
see below from isp provider

Thank you for contacting WOW! my name is Josh.

I apologize for any inconvenience this may be causing, but unfortunately the servers running our customer webspace currently only support HTML, DHTML, and JAVA Script. That being said, at this time for our free web space has no plans of supporting other languages such as PHP, ASP, or C++.

Again I apologize for any inconvenience this may be causing in the setup of your webspace.


Respectfully,

Josh - WDU
Tech Support
WOW! Internet, Cable and Phone
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:20 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.