Jump to content

I need help... I need a script that can read browser cookie.


Recommended Posts

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 

<?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?

<?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!

<?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.

<?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? ???

 

 

 

<?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  :'( :)

 

<?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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.