Log in

View Full Version : Resolved First time visitor be redricted to a welcome page



jackson
12-19-2008, 07:30 PM
Hi everyone,

I know next to zero about JS script. Sorry for I may be asking a stupid question. I am looking for a JS script that will redirect the first time visitor to a welcome page which has a flash introduction script, and if they have been to my site before, then they will be directed to the index page instead of welcome page. My site is a PHP site. Is it possible?

Thank you very much.

Nile
12-19-2008, 08:14 PM
Here's a PHP way of doing it. I've set a cookie and the cookie will last for two months or until the user clears their cookies.


<?php
if(isset($_COOKIE['been_here'])){
header('Location: index.real.php'); //change index.real.php to your index page
} else {
$two_months = 60 * 60 * 24 * 60 + time();
setcookie('been_here', true, $two_months);
header('Location: flash.php'); //change flash.php to your desired location for 1st timers
}
?>

jackson
12-19-2008, 08:26 PM
Here's a PHP way of doing it. I've set a cookie and the cookie will last for two months or until the user clears their cookies.


<?php
if(isset($_COOKIE['been_here'])){
header('Location: index.real.php'); //change index.real.php to your index page
} else {
$two_months = 60 * 60 * 24 * 60 + time();
setcookie('been_here', true, $two_months);
header('Location: flash.php'); //change flash.php to your desired location for 1st timers
}
?>


Sorry Nile,

May I ask where do I put this script? Do I make a new PTL and PHP pages, or do I put it into header? Thanks for your help.

magicyte
12-19-2008, 08:30 PM
If your server supports PHP (which many do), put that code into your .php page (you'll want to save it as .php). It's just like having regular code. Take an HTML page, for example. Just put the code Nile provided into the <head> or wherever you want it and the pre-processor will do the rest.

-magicyte

Nile
12-19-2008, 08:36 PM
What you want to do is put that in your index.php, if you want it to redirect to another page(if someone has already been to the site) then you would beed to change that in the code. If you just want it to stay on the same page if someone has already been to your site use this:


<?php
if(!isset($_COOKIE['been_here'])){
$two_months = 60 * 60 * 24 * 60 + time();
setcookie('been_here', true, $two_months);
header('Location: flash.php'); //change flash.php to your desired location for 1st timers
}
?>

And put it above everything else.
This code maybe a little bit easier for you to use:


<?php
$location = array();//make an array
$location[0] = "#"; //This is the location you want it to go if someone has been to your site, if you want it to stay on the same page use #.
$location[1] = "flashIntro.html"; //This is the location you want someone to go if they have not been to your site, to stay on the same page use #.

if(isset($_COOKIE['been_here'])){ //see if the cookie exists
if($location[0]!='#'){ //if it does, check and see if the location[0] doesn't equals #
header("Location: $location[0]"); //if it doesn't redirect to location [0]
} else { //if it does
//go nowhere, stay put
}
} else { //If there isn't a cookie called been_here with a value of "true" or 1, or a true statement
$two_months = 60 * 60 * 24 * 60 + time(); //2 months
setcookie('been_here', true, $two_months); //set a cookie called been_here with a true statement
if($location[1]!='#'){ //check to see if the location[1] doesn't equal #
header("Location: $location[1]"); //if it doesn't redirect to location[1]
} else { //if it does
//go nowhere, stay put
}
}
?>

Put it above everything else.
If you want to redirect to a different page when someone has been to your site before change the value of $location[0] to the location you want it at. If you don't want it to redirect change it to '#' which tells the script to stay put.

If you want to redirect to a different page when someone has not been to your site, change the value of $location[1] to the location you want it at. If you don't want it to redirect change the value to: '#'.

jackson
12-20-2008, 06:10 PM
What you want to do is put that in your index.php, if you want it to redirect to another page(if someone has already been to the site) then you would beed to change that in the code. If you just want it to stay on the same page if someone has already been to your site use this:


<?php
if(!isset($_COOKIE['been_here'])){
$two_months = 60 * 60 * 24 * 60 + time();
setcookie('been_here', true, $two_months);
header('Location: flash.php'); //change flash.php to your desired location for 1st timers
}
?>

And put it above everything else.



Hi Nile,

I just put these codes in my index.php, and it works perfectly. Will the cookie expire in two months? How can I change it to last until the users clear the cookies which may be longer than 2 months? Thank you very much for all of your help.

jackson
12-20-2008, 06:12 PM
If your server supports PHP (which many do), put that code into your .php page (you'll want to save it as .php). It's just like having regular code. Take an HTML page, for example. Just put the code Nile provided into the <head> or wherever you want it and the pre-processor will do the rest.

-magicyte

My page is working perfectly now. Thank you very much for your help.

Nile
12-21-2008, 01:38 AM
Ok, well I don't know which code your using, but I highly suggest this one:


This code maybe a little bit easier for you to use:


<?php
$location = array();//make an array
$location[0] = "#"; //This is the location you want it to go if someone has been to your site, if you want it to stay on the same page use #.
$location[1] = "flashIntro.html"; //This is the location you want someone to go if they have not been to your site, to stay on the same page use #.

if(isset($_COOKIE['been_here'])){ //see if the cookie exists
if($location[0]!='#'){ //if it does, check and see if the location[0] doesn't equals #
header("Location: $location[0]"); //if it doesn't redirect to location [0]
} else { //if it does
//go nowhere, stay put
}
} else { //If there isn't a cookie called been_here with a value of "true" or 1, or a true statement
$two_months = 60 * 60 * 24 * 60 + time(); //2 months
setcookie('been_here', true, $two_months); //set a cookie called been_here with a true statement
if($location[1]!='#'){ //check to see if the location[1] doesn't equal #
header("Location: $location[1]"); //if it doesn't redirect to location[1]
} else { //if it does
//go nowhere, stay put
}
}
?>



To change it from two months find the following line:

$two_months = 60 * 60 * 24 * 60 + time(); //2 months

jackson
12-21-2008, 01:54 AM
Ok, well I don't know which code your using, but I highly suggest this one:


To change it from two months find the following line:

$two_months = 60 * 60 * 24 * 60 + time(); //2 months

Thank you Nile,

I have used the codes that you suggested above. It works perfectly. I found the code
$two_months = 60 * 60 * 24 * 60 + time(); //2 months, if I want to change the 2 months to forever, what should I change? It sounds a stupid question, but I really don't know what to change. Sorry...

Jack

Nile
12-21-2008, 07:07 AM
There is no way to make it last forever, but you can make it last an amount of days:


$two_months = strtotime('+365 days'); //2 months

jackson
12-21-2008, 07:11 AM
There is no way to make it last forever, but you can make it last an amount of days:


$two_months = strtotime('+365 days'); //2 months



Thank you very very much for all of your help.

Nile
12-21-2008, 05:38 PM
Glad to help. :)

cyb3rs
07-07-2010, 09:38 PM
Hi.

Found the script using google.

Is there a way to see the refering url ?

I'd like to give the user the option to continue to the original url that he was visiting (skip the welcome screen)

I've tried with the following code, but it doesnt work. I guess its because of the redirect or something?


$ref = getenv("HTTP_REFERER");
echo $ref;


thx

EDIT:

btw, any idea on how will the search engines see the page, any negative impact or similar ?

djr33
07-21-2010, 01:27 PM
This reply is a bit late, and I'm not sure I understand your question.
Is the problem with getenv()?

Try: $_SERVER['HTTP_REFERER']