...

View Full Version : Require Issue



phil1ooo
05-27-2011, 07:27 AM
Hello

I have an issue with a new website which I installed. My problem is with the "require ("page")" calling code which is causing a problem I have never seen before.

Discription; To access the user pages (index.php) the require code needs to be set to ("index.php") but to access my Admin pages I need to change this require code to ("../index.php") for it to work.

I have tried placing the full URL there but that just stops everything from working. I also tried putting both calling codes there but that also doesn't work.

Does anyone have any idea on how I can fix this issue please as going to my files constantly to change this from one to the other is just not only annoying but also closes the website down when I am accessing the Admin.

Cheers

tangoforce
05-27-2011, 10:07 AM
You need to show your code for us to see whats going on.

Secondly require doesn't work with URLs so you'd best use a file system path instead. If you want to get something via a url use file_get_contents() instead (note that it won't get php code though - because it will run on that remote system as normal).

phil1ooo
05-27-2011, 10:38 AM
Hello

My code is

<?
require ("includes/db.php");
$get_globals = mysql_query("SELECT * FROM settings LIMIT 0,1")or die(mysql_error());
?>

This is the require which is in my config_global.php file which is used to call the website up.


The db file just has my database details and that is it.

The error message I get when trying to access the Admin is



Warning: require(includes/db.php) [function.require (http://www.ozydomainnames.com.au/admin/function.require)]: failed to open stream: No such file or directory in /home/MySite/public_html/MySite/admin/conf_global.php on line 3

Warning: require(includes/db.php) [function.require (http://www.ozydomainnames.com.au/admin/function.require)]: failed to open stream: No such file or directory in /home/MySite/public_html/MySite/admin/conf_global.php on line 3

Fatal error: require() [function.require (http://www.ozydomainnames.com.au/admin/function.require)]: Failed opening required 'includes/db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/MySite/public_html/MySite/admin/conf_global.php on line 3


Line 3 is the require field code line. As mentioned earlier when I add (../) I then can access the Admin panel but the website shows this message instead.

Cheers

tangoforce
05-27-2011, 10:39 AM
Discription; To access the user pages (index.php) the require code needs to be set to ("index.php") but to access my Admin pages I need to change this require code to ("../index.php") for it to work.

Please show THAT code. Not something irrelevant.

tomharto
05-27-2011, 12:15 PM
Use / first. If the full path to the file is www.mysite.com/includes/db.php put the path to
require("/includes/db.php");

If the full path to the file is www.mysite.com/MySite/includes/db.php put the path to
require("/MySite/includes/db.php");

Fou-Lu
05-27-2011, 02:44 PM
Do not use / first. That is useful in an HTML format as it resolves to DNS point, / in PHP will resolve to filesystem root. It is mostly unlikely that the system has a /includes on it. In other words, the full path to the file may be something like /user/yoursite/public_html/includes/file.php.

The problem is simple, but not enough information has been provided. The error indicates that no file exists at this location (not a privilege problem as the error would indicate its not able to open the file for reading).
Check your paths again. Also note that PHP will always resolve paths from the directory of the currently executing script (when used through a web service; CLI differs from this), so including a file which includes another file will resolve to different locations than intended. Using cwd() and chdir() or absolute paths (either explicit or variable generated) will solve that issue.

abduraooft
05-27-2011, 03:04 PM
Try the absolute path as below.
require ($_SERVER['DOCUMENT_ROOT']."/includes/db.php");

phil1ooo
05-27-2011, 03:28 PM
Try the absolute path as below.
require ($_SERVER['DOCUMENT_ROOT']."/includes/db.php");


That worked and solved the problem.

thank you very much for your help.

phil1ooo
05-27-2011, 03:30 PM
Please show THAT code. Not something irrelevant.

It was that code as it was shown here. Not suppling the correct info wounldn't get me very far now and also waste good peoples time.

tangoforce
05-27-2011, 05:03 PM
You'd be surprised how many people do show irrelevant code and i could see nothing there that referred to your main or admin page that you started off telling us about.


Hello
Discription; To access the user pages (index.php) the require code needs to be set to ("index.php") but to access my Admin pages I need to change this require code to ("../index.php") for it to work.


You are quite clearly showing index.php. What you were having a problem with was including your database driver file - something totally different.

If you're having a problem including your DB driver then say just that. No need to say about admin and main pages being used in require_once() as that only confuses the matter.

phil1ooo
05-27-2011, 10:29 PM
You'd be surprised how many people do show irrelevant code and i could see nothing there that referred to your main or admin page that you started off telling us about.



You are quite clearly showing index.php. What you were having a problem with was including your database driver file - something totally different.

If you're having a problem including your DB driver then say just that. No need to say about admin and main pages being used in require_once() as that only confuses the matter.

The problem had to do with the way the file was being called, not the bd file it's self. I'm pretty sure I mentioned it was a calling code issue and not a db issue.

Anyway the problem was fixed using "abduraooft" suggestion as I have tried them all as they where suggested to me.

Thank You. This topic is now CLOSED.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum