Mr_J Posted September 16, 2008 Share Posted September 16, 2008 Ok, I`m learning: I have created a LIBRARY File called tax.php. That only contains add_tax and add_tax_rate functions in the php tags. Now, I want to incorporate tax.php in my load20.php. include "tax.php" does not work so I used include ('http://medbel.co.za/jaco/sams2/tax.php') code: <?php $price = 95; include ('http://medbel.co.za/jaco/sams2/tax.php') //absolute location echo "Price before tax: $price <br>"; echo "Price after tax: "; echo add_tax($price); ?> Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/ Share on other sites More sharing options...
metrostars Posted September 16, 2008 Share Posted September 16, 2008 include 'tax.php'; should work. Just make sure both files are in the same folder, or use ../ or foldername1/foldername2/ etc. There is also a problem with tax.php itself: Parse error: syntax error, unexpected ';', expecting '{' in /usr/www/users/medbqq/jaco/sams2/tax.php on line 2 so make sure you fix that as it may be the problem. Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642713 Share on other sites More sharing options...
Mchl Posted September 16, 2008 Share Posted September 16, 2008 You're missing a semicolon ( ; ) in the include line Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642714 Share on other sites More sharing options...
Mr_J Posted September 16, 2008 Author Share Posted September 16, 2008 The err: Warning: main() [function.main]: URL file-access is disabled in the server configuration in /usr/www/users/medbqq/jaco/sams2/load20.php on line 2 Warning: main(http://medbel.co.za/jaco/sams2/tax.php) [function.main]: failed to open stream: no suitable wrapper could be found in /usr/www/users/medbqq/jaco/sams2/load20.php on line 2 Warning: main() [function.include]: Failed opening 'http://medbel.co.za/jaco/sams2/tax.php' for inclusion (include_path='.:/usr/share/php') in /usr/www/users/medbqq/jaco/sams2/load20.php on line 2 Price beforer tax: 95 Price after tax: Fatal error: Call to undefined function: add_tax() in /usr/www/users/medbqq/jaco/sams2/load20.php on line 6 The CODE: <?php include ('http://medbel.co.za/jaco/sams2/tax.php'); $amount = 95; echo "Price beforer tax: $amount"; echo " Price after tax: "; echo add_tax($amount); echo "To incorporate an external library file into another script: use INCLUDE <br>"; print "The following includes tax.php so I can call add_tax <br>"; ?> ??? Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642720 Share on other sites More sharing options...
Andy-H Posted September 16, 2008 Share Posted September 16, 2008 Your host has disabled calling includes on URL's as it can be used to call files from external servers and is a security risk. Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642721 Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2008 Share Posted September 16, 2008 Including a file using a URL does NOT include the php code. It only includes any content that is output by that file. You must use a file system path to include php code. A URL is not an absolute file system path. Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642723 Share on other sites More sharing options...
Mr_J Posted September 16, 2008 Author Share Posted September 16, 2008 Including a file using a URL does NOT include the php code. It only includes any content that is output by that file. You must use a file system path to include php code. A URL is not an absolute file system path. What is the "system path" then? root perhaps? Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642725 Share on other sites More sharing options...
Prismatic Posted September 16, 2008 Share Posted September 16, 2008 <?php include ("tax.php"); $amount = 95; echo "Price beforer tax: $amount"; echo " Price after tax: "; echo add_tax($amount); echo "To incorporate an external library file into another script: use INCLUDE "; print "The following includes tax.php so I can call add_tax "; ?> WILL work assuming tax.php is in the same directory you're calling load20.php from The system path is just where the file resides on the server. This is most always different on every machine. If you're unsure of your servers configuration simply running the following code in the same directory as load20.php will tell you the full system path to that file <?php echo getcwd(); ?> However absolute paths aren't required in most cases and a relative path will suffice, for example if tax.php is in the same folder as load20.php you can just call include("tax.php"); if tax.php is in a folder ABOVE the folder load20.php is in, you get to it with include("../tax.php"); if it's BELOW the folder load20.php is in you include it with include("/folder/tax.php"); I can tell you right now the full path is "/usr/www/users/medbqq/jaco/sams2/" from your error you posted before, but like I said, you dont need it. Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642740 Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2008 Share Posted September 16, 2008 A file system path is a path that has meaning to the file system used by the operating system on the server. An absolute file system path can be formed using $_SERVER['DOCUMENT_ROOT'] and your path/filename - include($_SERVER['DOCUMENT_ROOT'] . "/your_path/your_file.php"); Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642746 Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2008 Share Posted September 16, 2008 include("/folder/tax.php"); That would refer to the root of the current disk drive. Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642748 Share on other sites More sharing options...
Prismatic Posted September 16, 2008 Share Posted September 16, 2008 Don't tell me... Leading slash? Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642751 Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2008 Share Posted September 16, 2008 A leading slash on a file path refers to the disk root. Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642756 Share on other sites More sharing options...
Mr_J Posted September 16, 2008 Author Share Posted September 16, 2008 Thanks to all of you This is the code for tax.php: <?php function add_tax($amount) { $total = $amount * 1.14; return $total; } ?> This is the code for load20.php: <?php include ("tax.php"); $amount = 95; echo "Price beforer tax: $amount <br>"; echo " Price after tax: <br>"; echo add_tax($amount); echo "To incorporate an external library file into another script: use INCLUDE <br>"; echo "The following includes tax.php so I can call add_tax"; ?> Hope it helps someone in the future... tax.php is in the same folder as load20.php http://medbel.co.za/jaco/sams2/load20.php I just made a small thingie for my own reference... Cheers Link to comment https://forums.phpfreaks.com/topic/124463-solved-quotincludequot-to-noob/#findComment-642759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.