php_include override doesn’t work

Question:

Hi,

I can not override the php include_path from my .htaccess file. Running my php script gives ‘failure opening xxx.inc’ and still lists the default include path!

I’m sure my syntax is correct – why won’t this work?

Answer:

I noticed you are using one of the cgi-based php versions. When running these you must use your own php.ini file.

.htaccess has no effect. .htaccess only works with the mod_php apache module.

To set php options using the cgi-based php versions, do the following:

1. Create the directory /home/your_username/etc/

2. Put your own custom php.ini file

This will solve the problem.

How can I set php’s include_path

Question:

How can I set php’s include_path?

Answer:

Quck fix for any version

With any version of php you can add this to the top of your script:

ini_set ( “include_path”,”.:/home/your_username/www/:/home/your_username/www/dir/subdir/” );

This is a good fix if for some reason you cannot get other methods to work.

In general though, you should use one of the next two methods:

When using cgi-based php
If you are using one of the cgi-versions of php, you can set this by editing

/home/your_username/etc/php.ini

If this is your first time editing php.ini you may need to create the etc/ dir and upload a default php.ini

When using mod_php php

If you are using the mod_php version, you can set this in a .htaccess file with :

php_value include_path ".:/home/your_username/www/:/home/your_username/www/dir/subdir/"

Still having problems?

If you get a 500 error, then there is a syntax error in your .htaccess file.

If the pages loads but you do not get the intended result, make a page with just:


< ? phpinfo(); ?>

in it. When you load this page it will show you all the php vars for the page. Make sure the path is set how you wanted it. If it is but your scripts still do not work you’ll need to adjust them or your scripts until you get what you want. It can be hard to get the right path since your scripts may be operating differently from what you expect.

Keep in mind:

Your base dir on the filesystem is always:

/home/your_username/

Your web base dir is (unless you’ve customized your base dir):

/home/your_username/www/

Using Microsoft FrontPage with php

Question:

Hi, I came across this page:

http://office.microsoft.com/en-us/assistance/HA011092991033.aspx

which seems to indicate that I can use php with FrontPage. Can you help me out?

Answer:

I checked out that link you sent. According to the link you do not need the frontpage extension at all for php coding.

However you do need to make some changes to the FrontPage editor program on your computer. The page recommends you:

1. Use :

script language="php"> and /script

tags

instead of

< ? php?> tags.

2. ShowConfigure PHP file extensions to open in Design view

If you are doing php coding it may be best to not use FrontPage at all. The items above that I copied from Microsoft’s page should solve most of the problems. However at times FrontPage may not recognize the php code and try to reformat it.

How to turn off session.use_trans_sid

Question:

I’m trying to run PHProjekt and it says I need to turn off session.use_trans_sid. How can I do this?

Answer:

No problem.

If you are the default setup, just make a .htaccess file in your www directory (or the directoy below in which you want it to have effect) and put the line:

php_flag session.use_trans_sid off

Of if you are running the php cgi option (in the php section of the control panel), make the dir:

/home/your_username_here/etc/

and upload your own custom php.ini with the value set in side the php.ini

Let me know if you need more help!

php command in .htaccess do not work

Question:

I’m having trouble changing PHP settings (e.g., setting magic_quotes_gpc to off) inside of .htaccess.

I put in command like:

php_flag magic_quotes_gpc 0ff
php_flag register_globals 0ff
php_flag html_errors 0ff

but they do not take effect.

Answer:

If you are running the php-cgi versions you’ll need to make the dir :

/home/your_username_here/etc/

and upload a default php.ini and modify that. php in your .htaccess won’t work. Instead the system will read your private php.ini in your etc directory.

No input file specified – php custom 404 errors

Question:

I am trying to create a custom 404 using php. However I just get the error “No input file specified”

Any ideas?

Answer:

This occurs when you are running php as a cgi and an non-existant php page is called. When php runs as a cgi the webserver never checks for valid files – it just sends the request straight to the php parser. The php parser does not return a 404, instead it errors with “No input file specified”

Add the following to your .htaccess (or create a .htaccess file if you don’t already have one) and it should fix it

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /file_that_does_not_exist

The code above will cause the server to check for valid files first and redirect to a file that does not exist and trigger the 404.

Google sitemap verification error (404 versus 200)

Question:

I have submitted my sitemap to google. During the verifiction process, google reports an error from their verification saying that the server is reporting a status 200 instead of an error 404.

Could you assist with this?

Answer:

This occurs when you are running php as a cgi and a non-existant php page is called. When php runs as a cgi the webserver never checks for valid files – it just sends it straight to the php parser. The php parse does not return a 404, instead it errors with “No input file specified”

Add the following to your .htaccess (or create a .htaccess file if you don’t already have one) and it should fix it

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /file_that_does_not_exist

The code above will cause the server to check for valid files first and redirect to a file that does not exist and trigger the 404.

session.auto_start

Question:

I am trying to use sessions in a php script. But, after reading some documentation I realized that the following line needs to be added to the php.ini file

session.auto_start = 1

Could you please add this line for the php.ini file for my account?

Answer:

You can add any php.ini command to your account by creating a .htaccess file.

I created a .htaccess file in your www dir with the command

php_value session.auto_start 1

in it. This should do what you want.

php cgi and $_SERVER[‘php_auth_user’] problems

Question:

I upgraded my version of PHP from 4.4.0 mod_php (scripts run as nobody) to 4.4.0 (run as my username), per the PHP version configuration panel. Now I am getting some authentication problems:

Since the upgrade I am finding that $_SERVER[‘PHP_AUTH_USER’] is now null, whereas before it was populated.

Answer :

Hi,

Try and use :

$_SERVER[‘REMOTE_USER’]

That should work. The cgi versions of php don’t have access to the HTTP vars. Check :

http://us2.php.net/features.http-auth

for more on this.