php - Cookie Not Available Sitewide -


After

I have two problems with the settings and retrieve the cookie.

  1. The cookie is loaded but can not be called until the page is refreshed. This means that cookie appears in the developer tool but when trying to use its value on the page it appears to be used on the page after refreshing the value.
  2. The cookie is not available in the entire domain and subdirectory. For example, if the user enters, then the cookie is destroyed on the go

    Here is my code:.

      $ ad_source = $ _GET ['source']; $ Date_of_expiry = time () + (86400 * 7); Setcookie ('ad_source', $ ad_source, $ date_of_expiry, '/'); If ($ _COOKIE ['ad_source'] == 'adwords_campaign_01') {Echo '... do something'; } Otherwise ($ _COOKIE ['ad_source'] == 'adwords_campaign_02') {Echo '... do something else'; }   

    I am trying to show different information on the entire site by determining which AdWords campaign the user clicked on.

    I prefer to install a session I do not usually use cookies, but in this case I want to be able to track the source for a long amount of time.

    After the text "itemprop =" text ">

    Everything is now working as expected, a little more informative information in cookies on this post. Has been of great help.

    1. Redirect the page to the user after setting the cookie. The second request cookie from the browser sends information relative to the server side value.

    2. See if $ ad_source is set before making cookies.

      Updated code:

        $ ad_source = $ _GET ['source']; $ Date_of_expiry = time () + (86400 * 7); If ($ ad_source) {setcookie ('ad_source', $ ad_source, $ date_of_expiry, '/', 'example.com'); If ($ _COOKIE ['ad_source'] == 'adwords_campaign_01') {header ('location: http://example.com/'); Echo '... do something'; } Otherwise ($ _COOKIE ['ad_source'] == 'adwords_campaign_02') {Header ('location: http://example.com/'); Echo '... do something else'; }}    

Comments

Popular posts from this blog

c# - Textbox not clickable but editable -

Matlab transpose a table vector -

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -