Cookies help

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Hey, I was wondering how I could set a cookie that redirects a visitor to a homepage after they visit a intro page. Is there a way to do this?
 

shinyPlastics

New Member
Messages
2
Reaction score
0
Points
0
Well you could always do something such as using to verify the cookie via PHP or Javascript and then have it setup a redirect via <meta> or if you are using flash there are actionscripts to take care of that action. If you can tell me which approach you are planning to take.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
probably a cookie with PHP or Javascript.
 

shinyPlastics

New Member
Messages
2
Reaction score
0
Points
0
Well, the thing to do if it's just a simple HTML/PHP page as the intro just make a redirect after so many seconds via <meta>

<meta http-equiv="refresh" content="10;URL=http://url" />

With 10 being how many seconds to wait.....

if you did something like

if( $_COOKIE['cookiename'] ) {
echo '<meta http-equiv="refresh" content="10;URL=http://url" />';
}
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
if( $_COOKIE['cookiename'] ) {
echo '<meta http-equiv="refresh" content="10;URL=http://url" />';
}

instead of the <meta ... /> you can use the following php code as long as you have not echoed or printed anything

PHP:
header("location:some_url.php");
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
um. I am just trying to store a cookie that tells my webpage that they have viewed the intro, and to send the reader to my main page. any way to do that? I am a noob at cookies. all i know is that they are yummy....lol
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
sry for double post, but I still need help on this issue.
 

-fedexer-

New Member
Messages
32
Reaction score
0
Points
0
I am no expert but you could go with something along the lines of:

# = the page you get redirected to if you have seen the intro already
PHP:
if(isset($_COOKIE['COOKIENAME'])){
header("Location: ./#.php");
}else{
setcookie("COOKIENAME", TRUE, time()+7200);
header("Location: ./#.php");
}

Note i use time()+7200 as an example, this would mean the cookie would expirse after 2hrs, you could increase this to days/weeks/months.

Not sure if this is what you were wanting or not, but i figured i would give some input.
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
on your intro page

PHP:
<?
	if(!empty($_COOKIE['visit']))
		header('location:somesite.php');
	$cookie_result = setcookie("visit", true, time() + 3600);
	if(!$cookie_result)
		$message = "Please enable cookies within your browser";
	else
		header('location:index.php');
?>

the timeout (time() + 3600) set to timeout after an hour, so you could set it to timeout several years later. this also checks to see if the browser supports cookies.
 

preetham

New Member
Messages
16
Reaction score
0
Points
0
Your landing page would be the intro page i guess.
If this is the case.. when the user visits the site for the first time set the cookie as follows... in the introduction page

<?php
if(isset($_COOKIE['cookie_name'])){
header('Location: http://www.example.com/mainpage.php');
}
else{
setcookie("cookie_name", true, time()+86400);
header('Location: http://www.example.com/mainpage.php');
}
?>

this will make sure that the user will not see the introduction page for one day. You can increase/reduce the time as how long a user will not see the introduction page.

As cookies can/may be disabled by the users, you can use sessions to have the same effect.

Put this code in the introduction page.
<?php
session_start();
if(isset($_SESSION['visited_intro'])){
header('Location: http://www.example.com/mainpage.php');
}
else{
$_SESSION['visited_intro'] = 'true';
header('Location: http://www.example.com/mainpage.php');
}
?>

Note: Here the user will not see the introduction page till the session lasts.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
solved already, just got the chance to post this. I used javascript. thnx tho.

LOCKED
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
sorry to bother you again, but the user can disable javascript too, in my opinion it's better to use php :p
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
....dont care..they can just see the intro, and send me a friggin email if they want to know why they keep seeing it....
 
Top