Need Help php error

ddeswal293

New Member
Messages
2
Reaction score
0
Points
0
Hi,i am new here i need help
i made a script it works fine for some days but today when i open my site it give me a error

Warning: include() function.include]: open_basedir restriction in effect. File(/usr/local/apache/htdocs/54353.php) is not within the allowed path(s): (/home/:/tmp) in <b>/home/ddeswal2/public_html/index.phpon line 81

Warning: include(/usr/local/apache/htdocs/54353.php) function.include]: failed to open stream: Operation not permitted in /home/ddeswal2/public_html/index.php on line 81

Warning: include() [function.include]: Failed opening '/usr/local/apache/htdocs/54353.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ddeswal2/public_html/index.php on line 81

i added this code to my index.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/54353.php';
?>
 

bhupendra2895

New Member
Messages
554
Reaction score
20
Points
0
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/54353.php';
?>

Change it to this, if file resides in public_html folder

PHP:
<?php 
 include '/home/ddeswal2/public_html/54353.php';
 ?>

And you can simply do this too


PHP:
<?php 
 include '54353.php';
 ?>
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
And you can simply do this too


PHP:
<?php 
 include '54353.php';
 ?>

... if and only if the page in question resides in the root directory -- and, let's face it, if you have documents of multiple types (or multiple categories of documents) and they all appear to be in the same directory, your URLs will wind up being far from friendly.

Requiring us to hard-code our public HTML directory is an unfortunate misconfiguration decision IMHO. We were, until recently, able to use $_SERVER["DOCUMENT_ROOT"] to point to the public HTML directory for our accounts, and that is the only sane way to set up a shared server. The PHP you write should require the minimum possible amount of configuration to move from server to server, and with this move we are being forced to hardcode a path to even get to a configuration file. Not very user (or developer) friendly.
 

bhupendra2895

New Member
Messages
554
Reaction score
20
Points
0
Requiring us to hard-code our public HTML directory is an unfortunate misconfiguration decision IMHO. We were, until recently, able to use $_SERVER["DOCUMENT_ROOT"] to point to the public HTML directory for our accounts, and that is the only sane way to set up a shared server. The PHP you write should require the minimum possible amount of configuration to move from server to server, and with this move we are being forced to hardcode a path to even get to a configuration file. Not very user (or developer) friendly.
I thought that $_SERVER["DOCUMENT_ROOT"] can't be available in shared hosting therefore this weird error (in bold text inside quote)was generated.
Warning: include() [function.include]: Failed opening '/usr/local/apache/htdocs/54353.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ddeswal2/public_html/index.php on line 81
It is really unfortunate because it will require more amount of configuration.Is this not available because php is not installed here as apache's module?
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Fairly certain $_SERVER[]; is enabled.. It looks like the OP was using something like XAMPP to code on his home server and hardcoded the path..

OP:

What server are you on?
 

DeadBattery

Community Support Team
Community Support
Messages
4,018
Reaction score
120
Points
0
@leafypiggy: Starka

@ddeswal293: where is 54353.php in relation to index.php ?
 

dlukin

New Member
Messages
427
Reaction score
25
Points
0
Fairly certain $_SERVER[]; is enabled.. It looks like the OP was using something like XAMPP to code on his home server and hardcoded the path..

Yes, it is enabled.

And bhupendra2895 is right. When you guys fiddled with the settings,
$_SERVER[ 'DOCUMENT_ROOT' ]is now set to '/usr/local/apache/htdocs'
for everybody. It does not point to '/home/cPanelUsername/public_html' like it did before.

It is the same problem that now requires any mod_rewrite code to use
RewriteBase / in order to function properly.
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Yes, it is enabled.

And bhupendra2895 is right. When you guys fiddled with the settings,
$_SERVER[ 'DOCUMENT_ROOT' ]is now set to '/usr/local/apache/htdocs'
for everybody. It does not point to '/home/cPanelUsername/public_html' like it did before.

It is the same problem that now requires any mod_rewrite code to use
RewriteBase / in order to function properly.

You should be defining your rewrite base anyways.
 

dlukin

New Member
Messages
427
Reaction score
25
Points
0
You should be defining your rewrite base anyways.

Well, when Staff fiddled with the settings they broke a lot of scripts. Which is funny because one of the reasons cited for not upgrading Python/PHP versions has been that it would "break existing scripts".
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
How do you know, and when did we "fiddle" with scripts?
 

dlukin

New Member
Messages
427
Reaction score
25
Points
0
Friday, June 4
HTTP Changes

Earlier this evening we implemented a new Apache and PHP setup on two of our free hosting servers, chopin and cossacks. This new setup will allow us to completely stop Apache from ever needing to be restarted, drastically improving performance.

Along with this setup comes increased security measures. If your site or files are showing as 500 errors, ensure your permissions are not 777.

Update 1: Users with programs installed (Joomla, Drupal with SEO-friendly URLs) relying on Apache’s mod_rewrite have reported various issues. Also reported has been a fix, adding “RewriteBase /” to their mod_rewrite-enabled public_html/.htaccess.

Update 2: We have resolved an error affecting Apache’s document root enviromental variable.

Update 3: This new Apache configuration has been enabled on our free hosting server Boru.

...
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
It seems you can't fix DOCUMENT_ROOT in .htaccess, but you can set another environment variable (e.g. DOC_ROOT) and use that instead:
Code:
SetEnv SetEnv DOC_ROOT /home/ddeswal2/public_html
That way, if you change hosts, all you need to do is update that one line.

You can also add the document root to the include path. It requires a little more work, but you can also set up other things this way. At the top level, create an init.php:
PHP:
<?php
if (!function_exists('addToIncludePath')) {
  // add a directory to the include path only if it's not already there
  function addToIncludePath($path) {
      $currIncPath = ini_get('include_path');
      if (!preg_match('#(^|' . PATH_SEPARATOR . ')'.preg_quote($path, '#').'(' . PATH_SEPARATOR . '|$)#', $currIncPath)) {
		  set_include_path($currIncPath . PATH_SEPARATOR . $path);
      }
  }
}

addToIncludePath(dirname(__FILE__));
// or:
// addToIncludePath($_ENV['DOC_ROOT']);
// scripts outside web hierarchy
addToIncludePath(dirname(dirname(__FILE__)) . '/include/php');

// perform any other site-wide setup

With PHP 5.3, you can use __DIR__ rather than dirname(__FILE__).

In each subfolder, create an init.php that includes the parent init.php:
PHP:
<?php 
include_once(dirname(__FILE__) . '/../init.php'); 
// perform any other setup for this section of the site
?>
In each script, include "init.php".
 
Last edited:
Top