Jump to content

Error calling function from included file

- - - - -

  • Please log in to reply
2 replies to this topic

#1
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I have the following PHP script
<?php

$contentpage = "http://www.example.com/about/page.php";

require("http://www.example.com/passprotect.php");

if (function_exists('showpage'))

	{

	echo "2: function declared";

	}

else

	{

	echo "2: function not declared";

	}

showpage();

?>
And 'www.example.com/passprotect.php' contains
<?php

function showpage()

	{

	/*

	A long is function for password protected webpages

	...

	*/

	if ($passValid)

		{

		require($contentpage);

		}

	}

if (function_exists('showpage'))

	{

	echo "1: function declared";

	}

else

	{

	echo "1: function not declared";

	}

?>
The function is declared when the second PHP page is require()'d but then it creates an error when I try and call it again.
Is there anything I can do about this?

---------- Post added at 01:46 PM ---------- Previous post was at 01:44 PM ----------

I am relatively new to PHP so please excuse any stupid mistakes

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Why are you using the URL for the require, instead of the file name? Accessing it via a URL means you will just be receiving "1: function declared", not the function.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Ahh, okay, I fixed it now. Thanks a lot.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users