Jump to content

Php Cookies Help


gudipudi

Recommended Posts

Hello Friends,

 

my doubt is ...

 

when a person clicks on a link present on Page A, it should check for the cookies (if returning or new visitor) and should take him to 2 separate pages.

 

 

i.e Page A to Page B if returning visitor

    Page A to Page C if new visitor.

 

i having started learning php and if any one could provide me the working code, it  will help me a lot.

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/157439-php-cookies-help/
Share on other sites

Semi Simple solution, you want on all 3 pages a b and c to search for the cookie.. and if it exists then do something about it.. if not then do something else.. example:

 

<?php
if(!$_COOKIE['cookiename']) { include "page_C.php"; $_COOKIE['cookiename'] = "returnvisitor"; } // cookies not set show intro page.
elseif($_COOKIE['cookiename'] == "returnvisitor") { include "page_B.php"; } // cookie is set, and matches return tag, show return page.
else { include "page_C.php"; } // cookie is set that matches the cookie we are looking for but it doesnt match what we are looking for.
?>

 

Now thing is you can elaborate on this more such as verifying the cookie was set by your domain, how long till the cookie expires, and all else to further the security of the whole concept but the above will work or should work fine if your not doing anything that involves securing a section and its all about use ability and convenience.

Link to comment
https://forums.phpfreaks.com/topic/157439-php-cookies-help/#findComment-830022
Share on other sites

Disregard this part.. I was thinking something else prior to just doing it out like i did..

 

Semi Simple solution, you want on all 3 pages a b and c to search for the cookie.. and if it exists then do something about it.. if not then do something else.. example:

 

Put that code in your pageA.php instead of all 3

Link to comment
https://forums.phpfreaks.com/topic/157439-php-cookies-help/#findComment-830025
Share on other sites

 

<?php
if(!$_COOKIE['cookiename']) { include "page_C.php"; $_COOKIE['cookiename'] = "returnvisitor"; } // cookies not set show intro page.
elseif($_COOKIE['cookiename'] == "returnvisitor") { include "page_B.php"; } // cookie is set, and matches return tag, show return page.
else { include "page_C.php"; } // cookie is set that matches the cookie we are looking for but it doesnt match what we are looking for.
?>

 

Now thing is you can elaborate on this more such as verifying the cookie was set by your domain, how long till the cookie expires, and all else to further the security of the whole concept but the above will work or should work fine if your not doing anything that involves securing a section and its all about use ability and convenience.

 

i tried this...but it is opening only page C

Link to comment
https://forums.phpfreaks.com/topic/157439-php-cookies-help/#findComment-830164
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.