The in_array is correct, its the result thats incorrect. strcmp returns 0 and only 0 on success, not failure.
PHP Code:
if (!in_array($_SERVER['PHP_SELF'], $pages)) // Or embedded array, I'd use the variable like MattF has
{
.....
So the important part is the ! for the in_array, since the strcmp is only true on failure (where false === 0 and true != false in PHP). This will match the behaviour you currently have.
The problem here is the OP has a conflict in the code versus the definition of the code. The code specifies if (strcmp($_SERVER['PHP_SELF'],"/offline.php") != 0), which is so long as /offline.php is NOT $_SERVER['PHP_SELF'] (you may want to consider changing that btw, PHP_SELF is XSS exploitable), but the explaination you gave for this step is Line 2: Allow access to /offline.php (this is the bit I want to change to allow more files). Which is it supposed to be?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
First thank you for all your help, it now seems to be working as I want it
Quote:
Originally Posted by Fou-Lu
The problem here is the OP has a conflict in the code versus the definition of the code. The code specifies if (strcmp($_SERVER['PHP_SELF'],"/offline.php") != 0), which is so long as /offline.php is NOT $_SERVER['PHP_SELF']
I was given that code on a forum after asking how to only allow everyone access to offline.php but not anywhere else, unless the IP matched.
Quote:
Originally Posted by Fou-Lu
you may want to consider changing that btw, PHP_SELF is XSS exploitable
Try under $_SERVER['REQUEST_URI']. Test that on a couple nested directories as well, I think that will work as you want it to (but check, specifically for the /admin/offline.php you were asking about).
If not, also try under $_SERVER['SCRIPT_NAME'], that one I expect will need modifications though.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Try under $_SERVER['REQUEST_URI']. Test that on a couple nested directories as well, I think that will work as you want it to (but check, specifically for the /admin/offline.php you were asking about).
If not, also try under $_SERVER['SCRIPT_NAME'], that one I expect will need modifications though.
I tried $_SERVER['REQUEST_URI'] but that didn't work.
So I tried $_SERVER['SCRIPT_NAME'] which did work
One more question does $_SERVER['SCRIPT_NAME'] run ok under on Windows servers?
I tried $_SERVER['REQUEST_URI'] but that didn't work.
So I tried $_SERVER['SCRIPT_NAME'] which did work
One more question does $_SERVER['SCRIPT_NAME'] run ok under on Windows servers?
Yes, but. $_SERVER is never guarenteed to exist, its up to the environment to create these. Apache, IIS and CLI so far I've been able to retrieve REQUEST_URI and SCRIPT_NAME on. Generally, I use SCRIPT_NAME, but offhand I cannot recall what pathing it takes (absolute from filesystem root, or absolute from webroot; I was pretty sure it was filesystem root, but if it works in you're code here, thats likely from document root).
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php