根据php中重定向的页面更改id/class中的文本


Change Text in id/class based on the page they redirected from in php

我想根据他们重定向的页面更改div中的文本..

是否有任何if条件…或者任何帮助我做到这一点的代码…在网上搜遍了…但没有找到

如果用户从google.com我想显示你好googler!如果他来自我的朋友网站,你好XXX读者。( Xxx = my friends blog name)。如果他是直接访客,你好访客。像这样…

希望你们能帮助我!谢谢! !

在其他问题在stackoverflow,我发现这个代码(ASP.NET)我需要一个类似的php。

在这个ASP代码,他写ENDS WITH(" "),但我想写完整的url那里。

protected void Page_Load(object sender, EventArgs e)
{
  string requestUrl = "";
  . . .
  if (requestUrl.ToString().EndsWith("Page1.aspx"))
    label.Text = "foo";
  else
    label.Text = "bar";
}

谢谢!

$_SERVER['HTTP_REFERER']将完全满足您的需求。

if (strstr($_SERVER['HTTP_REFERER'], 'facebook.com') !== false) {
    // Facebook brought me to this page.
}
else if (strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false ) {
    // Google brought me to this page.
}

编辑

else if (strstr($_SERVER['HTTP_REFERER'], 'xxx.blogspot.com') !== false ) {
    // Your friend brought me to this page.
}