简体   繁体   English

PHP重定向Cookie问题

[英]PHP Redirect on Cookie Issues

Hi I want all my new / 1st users to my site to get redirected to a different page. 嗨,我希望我所有的新用户/第一用户都重定向到另一个页面。

Its a wordpress page and in the index.php file I have this code right on top 它是一个wordpress页面,在index.php文件中,我的代码在最上面

<?php
if ($_COOKIE['iwashere'] != "yes") { 
setcookie("iwashere", "yes", time()+20000);  
header("Location: http://howtobuygoldoffshore.com/sitemap"); 
exit;
}
?>

Now the issue is when I clear all cache and cookies from my browser and access this page it only goes to howtobuygoldoffshore.com instead of going to howtobuygoldoffshore.com/sitemap. 现在的问题是,当我从浏览器中清除所有缓存和cookie并访问此页面时,它仅转到howtobuygoldoffshore.com,而不是howtobuygoldoffshore.com/sitemap。

But now if I access it with a www.howtobuygoldoffshore.com then it goes to the correct landing page.(the www. is making some different I suppose) 但是现在如果我使用www.howtobuygoldoffshore.com进行访问,那么它将转到正确的登录页面。(我想该www会有所不同)

What could be the issue? 可能是什么问题? Is the code correct which I am writing and inserting in the index.php file or is there some issue with the re direction? 我编写并插入到index.php文件中的代码是否正确,或者重定向是否存在问题?

Your cookie isn't for all the subdomains on your site. 您的Cookie并非针对您网站上的所有子域。

setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] ) setcookie (字符串$ name [,字符串$ value [,整数$ expire = 0 [,字符串$ path [,字符串$ domain [,bool $ secure = false [,bool $ httponly = false]]]]]]]))

See the parameter $domain. 请参阅参数$ domain。 Try to save your cookie as $domain = howtobuygoldoffshore.com instead: 尝试将您的Cookie保存为$ domain = howtobuygoldoffshore.com

setcookie("iwashere", "yes", time()+20000, '/', 'howtobuygoldoffshore.com');

This will make your cookie work on both http://howtobuygoldoffshore.com and http://www.howtobuygoldoffshore.com . 这将使您的Cookie在http://howtobuygoldoffshore.comhttp://www.howtobuygoldoffshore.com上都能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM