Forum Moderators: coopster

Message Too Old, No Replies

PHP cookie on first page access

         

smallcompany

4:33 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I already read on many sites that if you want to “see” cookie set by a PHP procedure, you have to refresh the page or browse through the site.

In other words, people that get onto the page of our site and close the browser window or click onto an outgoing link on that page, they will not get a cookie written at all. Am I right?

Thanks

dreamcatcher

7:01 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you have specifically set a cookie somewhere then the visitor will have no cookie set on their machine.

dc

smallcompany

7:17 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Unless you have specifically set a cookie somewhere

I have a PHP script that loads before HTML code (from php.ini). Would this cover your statement or I need to do more?

As of now, cookie does not show up in cookies folder when you land onto my site, but only after refresh or once you start browsing through.

Thanks

dreamcatcher

8:04 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there some reason you don`t want a cookie set? What are you attempting to accomplish?

dc

smallcompany

8:31 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry for confusion.

I do want cookie to be set. It is just that I physically see that it’s not showing up when I just land onto my site. Once I click onto any internal link, it does show in “cookies” folder.

To repeat, I already came across claims that in order to get PHP based cookie written, more than just a “land” onto a site is needed (like page refresh).

So, right now, I am looking for a confirmation if this is 100% true or not.

My goal is simple: to have a cookie written right away as soon as you “touch” my site.

dreamcatcher

11:05 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is correct. This is from the PHP site:

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays.

So ideally you set the cookie on a landing page, then redirect.

dc

smallcompany

4:38 pm on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I thought about redirect. And I guess that is the only way to ensure the cookie is written, right? Are there other PHP based solutions?