1

I am trying to check if index.php or tob.php is in the URL of the current page. So, I tried to open:

/sbfc/public/HR/0-bg.php

It gives me false, which is expected. However, when I tried to open:

/sbfc/public/tob.php

Its return value is still false.

Any suggestion to rectify this issue? I do have queries in it, i supposed that that isn't the source of issue since i am using "PHP_SELF" instead of "QUERY_STRING".

Thanks in advance!

Edit: /sbfc/public/HR/0-bg.php and /sbfc/public/tob.php are the result of "PHP_SELF"

erwinleonardy
  • 486
  • 8
  • 14

1 Answers1

0

Because in_array() will only search for an exact match of a string. You may be looking for strpos() as that will find the first occurrence of a substring in a string. You can use a loop through the array and using strpos() on each iteration to find tob.php

Luke Brown
  • 1,854
  • 2
  • 28
  • 49
  • The data type of $_SERVER['PHP_SELF'] per se is not a string, i should convert it to string first in order to use strpos(). I decided to write the absolute path instead of merely /tob.php, and it works! That is strange, i once used in_array() the exact way and it worked. Anw, thanks a heap for the explanation! – erwinleonardy Jan 20 '16 at 11:52
  • For in_array() the datatypes shouldn't necessary make a different, you can force it to match the datatype that you are using by enabling strict mode (by adding true as a final parameter when using the function). There is more documentation on the PHP website regarding this functionality. Alternatively, [array_filter](http://php.net/manual/en/function.array-filter.php) might be more helpful to you as I found in [this question](http://stackoverflow.com/questions/5749415/search-for-a-string-or-part-of-string-in-php). – Luke Brown Jan 21 '16 at 17:09