开发者

Cookie to check if user has been before if not then redirected to home page

Hi I’m trying to use the following cookie to force users to go to my homepage first no matter what link they come to me from (I know a lot of people frown upon this but it’s something i wish to do) if they haven't been to my homepage before:

I have the following code on my home page between the “head” tags:

$.cookie(“seenhp”, true, { expires: 36开发者_StackOverflow5 });

And the following code on every other page between the “head” tags again:

if (!$.cookie(“seenhp”)) location.assign(“/index.php”);

It doesn’t seem to be working am i missing something very obvious?


you tagged this with PHP, but I cant see any PHP code here. This looks more like jquery? Have you included jquery?

Well the PHP way would be

setcookie("seenhp", "seenhp");

and

if(!isset($_COOKIE["seenhp"])){
    header("Location: http://home.page/");
    die();
}

Not meaning to be offinsive, but please try to understand what you're doing. Reading the other thread, i guess you don't use:
https://github.com/carhartl/jquery-cookie

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜