TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-03-2010, 06:15 AM   #1 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Help Setting Cookie...

I have a cookie being set but the page needs to be refreshed for the cookie to be written to the page? I have the set_cookie command in the header of my file (before html tags) but even though I've confirmed with the browser the cookie was set It does not write the cookie to the page. After hitting refresh, it is then written to the screen?

Anyone ever come across this? Is there a fix or some thing i'm doing wrong? I have 3 php files, header. php, results.php and footer.php. The form action is to results.php but that page includes the header.php file so shouldn't the cookie be set during the header.php load and then results.php write the cookie?

gillweb is offline  
Reply With Quote
Old 11-03-2010, 04:11 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by gillweb View Post
I have a cookie being set but the page needs to be refreshed for the cookie to be written to the page? I have the set_cookie command in the header of my file (before html tags) but even though I've confirmed with the browser the cookie was set It does not write the cookie to the page. After hitting refresh, it is then written to the screen?

Anyone ever come across this? Is there a fix or some thing i'm doing wrong? I have 3 php files, header. php, results.php and footer.php. The form action is to results.php but that page includes the header.php file so shouldn't the cookie be set during the header.php load and then results.php write the cookie?

I'm not quite sure what you are asking. The cookie is set when the page is sent out, no refresh is needed for it to be there. What you may be doing is this:

PHP Code:
//Current cookie data
//Data:1001
//Lets change this
setcookie('data','2002');
echo 
$_COOKIE['data']; //Will output 1001 
The $_COOKIE variable is set at the beginning of every request with what the cookie data is. Setting a new cookie does not change the $_COOKIE array, although the user's cookie will be changed when the page outputs.
__________________

Village Idiot is offline  
Reply With Quote
Old 11-03-2010, 04:20 PM   #3 (permalink)
The Wanderer
 
Join Date: Feb 2008
Posts: 13
Thanks: 3
gillweb is on a distinguished road
Default

thats sort wht i was doing. You put me in the right direction thanks. What iv'e done is told my page that if the form is submitted to set the cookie to the redirect to that forms "action" page with the parameters set by the form and this works pretty well.

Quote:
If ( $set_cookie == 'yes' ) {
$area_location = $_GET['area-location'];
$service = $_GET['service'];
setcookie("county", "$area_location");
header( 'Location: results.php?area-location='.$area_location.'&service='.$service.'' ) ;
} else {
}
gillweb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving ALL the cookie data using cURL Wildhoney Advanced PHP Programming 1 06-12-2008 07:07 PM
Best Way To Delete A Cookie? StevenF Absolute Beginners 11 03-08-2008 03:36 PM
encoding cookie content Devels General 7 02-21-2008 01:56 PM
Cookie issue -jQuery Sam Granger Javascript, AJAX, E4X 0 12-14-2007 01:44 PM
Taking a Bite out of the Set Cookie Function Wildhoney General 2 09-29-2007 07:52 AM


All times are GMT. The time now is 09:11 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design