-3

I'd like to check for both session and http referer but it's not working for me.

First page:

<?php
session_start();
$_SESSION['something'] = '1';
?>

Second page:

<?php
session_start();
  if(!strpos($_SERVER["HTTP_REFERER"], "some referer")){

    die(header("Location: my site"));
  }

  if(!isset($_SESSION['something'])){

      die(header("Location: my site"));
  }

session_destroy();
// rest code

What am I doing wrong?

Shaz
  • 1
  • 1

2 Answers2

1

Looks like you are experiencing unwanted type conversion.

strpos returns the index of the (partial) match inside the string. If you are checking for exactly the referer you want, it's returning 0 and evaluating to false, thus entering the condition.

Check for the return type of strpos explicitly either by:

if (is_bool(strpos($_SERVER["HTTP_REFERER"], "some referer")))

This means it returned false so it wasn't found, or more to the point:

if (strpos($_SERVER["HTTP_REFERER"], "some referer") === FALSE)
msg
  • 7,863
  • 3
  • 14
  • 33
0
if((!strpos($_SERVER["HTTP_REFERER"], "some referer")) || !isset($_SESSION['something'])){
    die(header("Location: my site"));
}

i think you need this condition

vivek modi
  • 487
  • 1
  • 5
  • 19