Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

require_once and/or include_path - not really working 1

Status
Not open for further replies.

jlockley

Technical User
Nov 28, 2001
1,522
US
class.PHPMailer.php is in /include/class.phpmailer.php

The include path in php.ini is set to read
include_path = ".:/include"

The second line of the beknighted mail script reads
include_once(class.phpmailer.php) or alernately
include_once(/include/phpmailer.php)

The browser sneers:


Warning: require_once(class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in /home/moi/public_html/mysite.com/gator2.php on line 2

Fatal error: require_once() [function.require]: Failed opening required 'class.phpmailer.php' (include_path='.:/include/') in /home/moi/public_html/mysite.com/gator2.php on line 2

in either case.

I am using a Cpanel interface on Hostgator. My interpretation of the file structure is that the classes are stored in /include/ but I am wondering if the feedback home/moi/etc isn't my problem.

I attempted chucking class.phpmailer.ini in the public directory with the script. It screamed for class.smtp.php, which I then threw in with it. At that point the browser displayed the contents of class.smtp.exe


 
you should use quotes in your include statements. the brackets are optional.

so far as I am aware phpmailer has no exe's within it. if you have one then this must be something else.

the error you are getting states simply that the file 'class.phpmailer.php' can not be found in the current working directory /home/moi/public_html/mysite.com/ nor can it be found in the directory /include/

php aint stupid. this means that the file is not in either of those two directories. perhaps the /include/ directory is not at the root of the filesystem but instead at the root of your home folder tree? or perhaps you have kept phpmailer in its own subdirectory inside /include (in which case you need to include 'phpmailer/class.phpmailer.php';

but why overcomplicate this? if you cannot get the scripts to work for you in another directory, just put them in a subdirectory of your CWD and reference them from there.

Code:
include '/home/moi/public_html/mysite.com/phpmailer/class.phpmailer.php';
 
I thought it was considered good policy to keep the included PHP files for feedback and mail forms in a separate directory. No?

Thanks. I will let you know if it works.
 
i'm not sure what you mean. but generally practice is dictated by what makes your code must comprehensible to someone other than yourself.
 
That makes a great deal of sense. I've actually got it working now. Unfortunately it returns the entire script of class.phpmailer.php, but it sends. Both your script and the other one. Now to get on with practical application.

As for the security matter, my understanding is that locating scripts in a distinct folder and using the require_once command were two advisable security measures. Of course something that is so secure it doesn't work, isn't a lot of use.
 
ah. i see what you mean.

it is good security practice to keep files that you don't want web accessible outside of the webroot. for example, images that you want only certain people to see, likewise documents etc and also identity credentials like database connection passwords.

this means that should php , for some reason, fail, apache won't start serving the raw php files and expose your credentials.

for ordinary scripts that are designed to be used within your application, i see no harm in these being under your webroot.
 
Ah! Makes sense. Thanks for everything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top