dongnong3799 2014-06-23 19:34
浏览 11
已采纳

如果url是mywebsite.com/url做某事

I am using WordPress to set a cookie for a specified page , but it can't be done by adding the php code on the page as with PHP, cookies are set in the web page header lines, before any page content is processed.

I found a solution and it's to edit the index.php file and adding the code in the top , but this will add the code for the all pages .

So i want a php code that will get the webpage url for example

if ($pageUrl == 'http://website.com/another_page')
 {
setcookie("cookie[one]","cookieone" , time()+3600*720); 
if (isset($_COOKIE["cookie"]))  
{
header("Location: http://website.com/page");
  } 
}

PS: The code above maybe broken .

  • 写回答

2条回答 默认 最新

  • dream_high1026 2014-06-23 19:42
    关注
    if($_SERVER['REQUEST_URI'] === "/page/1/blog"){
      // do code here
    }
    

    Request URI will give you the current URL after the domain name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?