質問

I am filtering a page with $_SERVER['HTTP_REFERER'].

Let "pageb.php" filter whether a user have come from "pagea.php" (although it is not reliable) by $_SERVER['HTTP_REFERER'].

It works well until "pagea.php" has a preceding query string like "pagea.php?q=10". Then if a user goes from "pagea.php?q=10" to "pageb.php" it is not detected by "pageb.php":

if($_SERVER['HTTP_REFERER']='http://pagea.php'){
 echo 'This user has come from page a';
}else{
 echo 'This user has come from another page';
}

How can I detect a user came from "pagea.php" even with preceding query string q=10?

役に立ちましたか?

解決

Use strpos() to check if a string contains another string:

<?php
if (strpos($_SERVER['HTTP_REFERER'], 'pagea.php') !== false) {
  echo 'from page a';
}

他のヒント

use comparision operator not assignment if($_SERVER['HTTP_REFERER']='http://pagea.php'){

= will be ==

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top