 | Senior Member with 368 posts. | | Join Date: Oct 2006 Location: Grafton, WI, USA Experience: Advanced | | 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. | | Member with 84 posts. | | Join Date: Jan 2006 Location: Nigeria Experience: Intermediate | | 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. | | Senior Member with 368 posts. | | Join Date: Oct 2006 Location: Grafton, WI, USA Experience: Advanced | | 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? | | Senior Member with 413 posts. | | Join Date: Apr 2007 Experience: Excel, Access, PHP, Js | | Does your browser have cookies on? | | Senior Member with 368 posts. | | Join Date: Oct 2006 Location: Grafton, WI, USA Experience: Advanced | | Yes, the cookie sets without any problems. I've verified this problem with Firefox, IE, and Opera. | | Member with 43 posts. | | | | 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. | | Senior Member with 368 posts. | | Join Date: Oct 2006 Location: Grafton, WI, USA Experience: Advanced | | 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 Also, attached is a screen capture of the user_first_name cookie that is set in my browser.
Thanks again! | | Senior Member with 368 posts. | | Join Date: Oct 2006 Location: Grafton, WI, USA Experience: Advanced | | 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! | | Senior Member with 660 posts. | | Join Date: Nov 2004 Experience: Advanced | | 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. | | Senior Member with 368 posts. | | Join Date: Oct 2006 Location: Grafton, WI, USA Experience: Advanced |
06-Jul-2009, 05: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. | | Senior Member with 660 posts. | | Join Date: Nov 2004 Experience: Advanced |
06-Jul-2009, 05: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. | | Senior Member with 660 posts. | | Join Date: Nov 2004 Experience: Advanced |
07-Jul-2009, 01: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 |  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.
| | |
Smart Search
| Find your solution! | | | |
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.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 09:19 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|