Pergunta

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?

Foi útil?

Solução

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

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

Outras dicas

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

= will be ==

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top