Jump to content

PHP is being stupid ... "undefined" function exists


johnl1479

Recommended Posts

index.php
[code]
<?php
require ("http://inc.johnluetke.net/site_status.php");

if (isRestricted("home")) {
    include ("http://inc.johnluetke.net/unavailable.php");
    die();
}
?>
[/code]

site_status.php
[code]
<?php
function isRestricted ( $page ) {

    $restrict = "home";
    
    if ($page == $restrict) {
        return true;
    }
    else if ($restrict == "all") {
        return true;
    }
    else {
        return false;
    }
}
?>
[/code]


when loading index.php, PHP tells me that isRestricted is undefined....am i missing something?
the purpose of the function is to see if the current part of the site is restricted. the name of the page in question is passed via the $page variable.

$restrict is the name of the page that cannot be viewed

the first if statement checks to see if the given page is resricted

the second sees if the whole site is restricted
From looking at your code, the secound if is checking whether $restrict is equal to "all", it is not checking whether $page is equal to "all", only the first if is checking the value of $page.

Also I have no idea why you're getting the undefined function error message. You are sure that you havn't mistyped the name of the function? Also with your require/include statements you can use relative paths rather then full paths.
you're including the file via the HTTP protocol which means your web server (eg: apache) will parse the file which means what you're including will be some form of makrup like HTML and not PHP.

if you want the raw PHP code, you would have to include it via the file protocol instead of http so that the PHP is not processed before it's included.


eg:
[code]
<?php
require ("/path/to/inc.johnluetke.net/site_status.php");

if (isRestricted("home")) {
    include ("http://inc.johnluetke.net/unavailable.php");
    die();
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.