freeak08 Posted November 1, 2007 Share Posted November 1, 2007 Guys, I need help... I'm basically a beginner, and I would just like to have a script. Is there a script/ or can you create a script that can read cookie on a website's viewers browser (cache)? My Idea is to run the script once viewers would actually load the index page of a website, then the website would actually load a certain page that would contain any related cookie information taken from the browser (if there is one, if none then the default index page would load. Please, please, please guys... I really believe the people here are very good in php, and I would really appreciate the help. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/ Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 post this in freelance section Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383132 Share on other sites More sharing options...
kratsg Posted November 2, 2007 Share Posted November 2, 2007 <?php if(isset($_COOKIE['somecookie']) && !empty($_COOKIE['somecookie'])){//a cookie exists and it's not empty $cookie_value = $_COOKIE['somecookie']; echo $cookie_value; echo "<b><center>$cookie_value</center></b>"; } else { include 'index.php'; } ?> I believe that's along the lines of what you want? Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383133 Share on other sites More sharing options...
freeak08 Posted November 2, 2007 Author Share Posted November 2, 2007 <?php if(isset($_COOKIE['somecookie']) && !empty($_COOKIE['somecookie'])){//a cookie exists and it's not empty $cookie_value = $_COOKIE['somecookie']; echo $cookie_value; echo "<b><center>$cookie_value</center></b>"; } else { include 'index.php'; } ?> I believe that's along the lines of what you want? I'm really sorry, but I really don't have too much idea about php, just starting to explore it.. could you kindly explain the lines and what it does exactly? Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383488 Share on other sites More sharing options...
kratsg Posted November 2, 2007 Share Posted November 2, 2007 <?php if(isset($_COOKIE['somecookie']) && !empty($_COOKIE['somecookie'])){//a cookie exists and it's not empty $cookie_value = $_COOKIE['somecookie']; echo $cookie_value; echo "<b><center>$cookie_value</center></b>"; } else { include 'index.php'; } ?> Line by line: If the cookie by the name of 'somecookie' exists, and it's value is not empty, then We set $cookie_value equal to the value of 'somecookie' and then echo out the value. Else, if it doesn't exist or it's empty, show the main page and do nothing with the cookie. Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383792 Share on other sites More sharing options...
freeak08 Posted November 2, 2007 Author Share Posted November 2, 2007 <?php if(isset($_COOKIE['somecookie']) && !empty($_COOKIE['somecookie'])){//a cookie exists and it's not empty $cookie_value = $_COOKIE['somecookie']; echo $cookie_value; echo "<b><center>$cookie_value</center></b>"; } else { include 'index.php'; } ?> Line by line: If the cookie by the name of 'somecookie' exists, and it's value is not empty, then We set $cookie_value equal to the value of 'somecookie' and then echo out the value. Else, if it doesn't exist or it's empty, show the main page and do nothing with the cookie. Hi thanks again for the help, it actually gave me hope that my idea would work, but to explain further what I would like to do: 1. I would like to have cookies set on each "first" page of my subdirectory. 2. I would like to use those cookies - If those cookies I have on my pages (on each subdirectory) exist or matches the cookies on browser of the viewer, it would open that page. (something like a redirect.) - now If I understand it correctly echo $cookie_value - would print out the "somecookie" can we set a command to open up a page? ??? Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383890 Share on other sites More sharing options...
freeak08 Posted November 2, 2007 Author Share Posted November 2, 2007 <?php if(isset($_COOKIE['somecookie']) && !empty($_COOKIE['somecookie'])){//a cookie exists and it's not empty $cookie_value = $_COOKIE['somecookie']; echo $cookie_value; echo "<b><center>$cookie_value</center></b>"; } else { include 'index.php'; } ?> Line by line: If the cookie by the name of 'somecookie' exists, and it's value is not empty, then We set $cookie_value equal to the value of 'somecookie' and then echo out the value. Else, if it doesn't exist or it's empty, show the main page and do nothing with the cookie. Hi thanks again for the help, it actually gave me hope that my idea would work, but to explain further what I would like to do: 1. I would like to have cookies set on each "first" page of my subdirectory. 2. I would like to use those cookies - If those cookies I have on my pages (on each subdirectory) exist or matches the cookies on browser of the viewer, it would open that page. (something like a redirect.) - now If I understand it correctly echo $cookie_value - would print out the "somecookie" can we set a command to open up a page? ??? Hi thanks again for the help, it actually gave me hope that my idea would work, but to explain further what I would like to do: - now If I understand it correctly echo $cookie_value - would print out the "somecookie" can we set a command to open up a page? ??? Now my idea is for a online store - that would have several products... now, I don't want my customers not to waste his/her time roaming the site, I would like the site to open a page that the customer wants to see... for example: i have a page for: jewelry, apparels, kitchen tools. I would set keywords like : ring, bracelets, silver, gold, diamond - for jewelry page : Tank tops, blouse, short, pants, skirts - for apparel : pans, oven, knife, spoon, fork, beater - for kitchen tools - the script (on my index.html page) would check my customer's cookies if it matches the keywords - when cookies on the browser of my client matches the keywords of one of my page it would pull that up that page, on one I-frame on my index.html Now can you help me with this...?? Thanks again :'( Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383902 Share on other sites More sharing options...
kratsg Posted November 3, 2007 Share Posted November 3, 2007 <?php if(isset($_COOKIE['somecookie']) && !empty($_COOKIE['somecookie'])){//a cookie exists and it's not empty $cookie_value = $_COOKIE['somecookie']; echo $cookie_value; echo "<b><center>$cookie_value</center></b>"; } else { include 'index.php'; } ?> Line by line: If the cookie by the name of 'somecookie' exists, and it's value is not empty, then We set $cookie_value equal to the value of 'somecookie' and then echo out the value. Else, if it doesn't exist or it's empty, show the main page and do nothing with the cookie. Hi thanks again for the help, it actually gave me hope that my idea would work, but to explain further what I would like to do: 1. I would like to have cookies set on each "first" page of my subdirectory. 2. I would like to use those cookies - If those cookies I have on my pages (on each subdirectory) exist or matches the cookies on browser of the viewer, it would open that page. (something like a redirect.) - now If I understand it correctly echo $cookie_value - would print out the "somecookie" can we set a command to open up a page? ??? Actually, that's a bit backwards... Say $_COOKIE['page_count'] as an example. index.php <?php //they loaded the page, let's see if the cookie exists first if(!isset($_COOKIE['page_count']) || !is_numeric($_COOKIE['page_count'])){//the cookie does not exist or it's value is not a number $_COOKIE['page_count'] = 0;//set this to zero since they've not been here or they tried to hack the cookie } else {//they have been here $_COOKIE['page_count']++;//increment the page_count by 1 } echo "Welcome, you have visited this page ".$_COOKIE['page_count']." time(s)."; ?> Stick that in a blank page, see how it works for you. It should keep adding '1' each time you refresh the page. Quote Link to comment https://forums.phpfreaks.com/topic/75708-i-need-help-i-need-a-script-that-can-read-browser-cookie/#findComment-383997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.