FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


issues with include of files





Dark-Tech
I have 3 php pages

1 is functions.php and holds all functions for the site
2 is index.php and pulls other scripts and codes together to form the site
3 is loginform.php which is a login form

when you visit index.php it calls a function in function.php called primurl which returns a stored value of the domain name / the root directory of the site.....

so the login script is called via a

require(primurl().loginform.php);
in the login form the action is primurl().processlogin.php


When the index reads
require(primurl().loginform.php);

i get a

Fatal error: Call to undefined function primurl() in /var/www/login/loginform.php on line 6

however if the index does not call primurl
require(loginform.php);

it works fine.

What could cause this ?
jmraker
It's because a function named "primurl" does not exist. It needs to exist before it's used and if it's in function.php the function won't exist until the file is used. You can use primurl() after it includes "functions.php".

You don't really need to specify the full path. You can use relative paths like '../functions.php' or 'include/functions.php' or just 'functions.php'

It might be better the save the base directory as a constant as in
Code:
define('primurl', '/home/site/public_files/')

and use
Code:
require_once(primurl . 'loginform.php');
riccopt
why do you need the primurl() function?
without seeing the complete code it is kind of hard to help you... but you could use something like DOCUMENT ROOT to call the files... or simply configure the path correctly...
jmraker
I'm guessing it's because the included files are in another directory and might not be access-able to the web server.
imagefree
the primurl() function saved in the function.php file, so the function.php file needs to be included before the function is called. the solution is simple. if you really want this type of file inclusion, you can first make a config file that is easily accessible through the relative addressing, and keep the primurl() function inside that config file, and then use that function to include any file.

in you donot want to keep a config.php file, then you have to use the solution jmraker provided above.
Related topics
Site Nav Suggestions...
Help with Website
PHP Tutorials
Artificial / Modified Food
A little help on C++
php/HTML pages question
php include
Xbox
Google Removal
Help please,"Forbidden You don't have permission to acc
Load scripts from another file
The World Cup and New Nationalism
150 frih to make this SIMPLE script
Help needed with images in php include files
Include files
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.