gudipudi Posted May 9, 2009 Share Posted May 9, 2009 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 More sharing options...
monkeytooth Posted May 9, 2009 Share Posted May 9, 2009 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 More sharing options...
monkeytooth Posted May 9, 2009 Share Posted May 9, 2009 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 More sharing options...
gudipudi Posted May 9, 2009 Author Share Posted May 9, 2009 <?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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.