Jump to content

Cookie with redirection


PAUSIMS

Recommended Posts

Hi everyone,

 

First of all I should apologise for my level of English, it's not good but anyway I hope you can understand me.

 

I'm absolutely new at Php and I want to create an index.html with a php cookie that if it's the first visit takes you to index2, if you already visited the site takes you to index3.

 

I found this code:

 

<?php

$visits = $visits + 1;
setCookie("visits",$visits,time() +3600*24*365);

?>
<html>
<body>
<?php
If ($visits > 1 {
Echo ("HERE NEEDS TO TAKE TO INDEX3");
} else {
Echo ("HERE NEEDS TO TAKE TO INDEX2");
}
?>
</body>
</html>

 

So, I don't know how to complete this code for the redirection where it says "here needs to take to index3" and "here needs to take to index2".

 

Also, if some of you know another code that could be more reliable and well done than the above one would be very appreciate.

 

Thanks in advance,

 

Pau

Link to comment
https://forums.phpfreaks.com/topic/177289-cookie-with-redirection/
Share on other sites

So I tried to add the require_once() function in the code but I think I made some mistake because it doesn't work.

 

As I said, I'm a completely newbie in Php and I'm very lost, so if someone could edit for me the avobe code adding the require_once() function or any other one that could redirect to an HTML page if it's the first visit of the user or if it's not the first visit, it would be very appreciate.

 

Thanks very much :)

OK, the require_once() does work but the cookie seems to not work. Even if it's the first visit it takes me to the page for subsequent visits... I deleted all the cookies of my browser but it still doesn't work.

 

The code is the following:

 

FILE: INDEX.PHP

 

<?php

$visits = $visits + 1;

setCookie("visits",$visits,time() +3600*24*365);

 

if ($visits > 1) {

require_once('first.php');

} else {

require_once('subseq.php');

}

?>

 

 

FILE: FIRST.PHP

 

<?php

header( 'Location: http://www.mysite.com/welcome.html ) ;

?>

 

 

FILE: SUBSEQ.PHP

 

<?php

header( 'Location: http://www.mysite.com/web' ) ;

?>

Archived

This topic is now archived and is closed to further replies.

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