Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 johnl1479

johnl1479
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationSac-a-tomatoes, CA

Posted 27 June 2006 - 05:05 AM

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

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

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

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


when loading index.php, PHP tells me that isRestricted is undefined....am i missing something?

http://john.redhedinsanity.net
--------------------
OS X - Apache 1.3.33 :: PHP 5.0.1 :: MySQL 5
Linux - Apache 1.3.33 :: PHP 4.3.11 :: MySQL 4.1.11

#2 tiki

tiki
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 27 June 2006 - 05:09 AM

site_status.php is confusing, why are you comparing home to all?

#3 johnl1479

johnl1479
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationSac-a-tomatoes, CA

Posted 27 June 2006 - 05:08 PM

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

http://john.redhedinsanity.net
--------------------
OS X - Apache 1.3.33 :: PHP 5.0.1 :: MySQL 5
Linux - Apache 1.3.33 :: PHP 4.3.11 :: MySQL 4.1.11

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 June 2006 - 06:09 PM

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.

#5 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 27 June 2006 - 06:47 PM

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:
<?php
require ("/path/to/inc.johnluetke.net/site_status.php");

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users