简体   繁体   中英

PHP setcookie function not being set on wordpress splash page implementation

So I'm trying to get a splash page implemented on a wordpress site. I've looked around and read about how to do it using PHP. The idea of the splash page is to redirect people that haven't viewed the site to a splash page that encourages them to donate. The page is already set to a static homepage which I am making the splash page be. Provided here is the code that I have for the cookie, for some reason when I go into my settings on chrome and check to see if the cookie is being written it doesn't show up.

<?php
  if((strpos($_SERVER['HTTP_REFERER'], get_bloginfo('home')) === false)  && !$_SERVER['QUERY_STRING'] && $_COOKIE["CookieName"] != 'true') :
  setcookie("CookieName", 'true', time() + 3600*24*15, "/~user/");
?>
//splash page code
<?php else : ?> //theme code <?php endif; ?>

The else condition is the information for the homepage that was created by the theme. The URL for the site is in the format of siteIP/~user/ . If you guys have some feed back that would be greatly appreciated. Also if you can provide a source so that I can read up on it that would also be appreciated. Thanks for your time.

Sorry for posting an answer but I can't comment because I don't have the rep.

Besides reviewing the comments above, try simplifying - check that the if statement is being executed, then you'll know if you have an error in the cookie setting.

Also, your code as quoted doesn't have a closing statement, I assume you have that in the actual page but thought I would mention that.

The reason that it didn't work is because there was a file that was overwriting the splash page itself so the code on the splash page wasn't being called in the first place. It's a matter of just naming files so that it doesn't have any additional files overwriting it the content that you put up there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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