Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

Execute php script before every php script?

How would I run this before every php script besides putting it in all of them?

if ($_SERVER['REMOTE_ADDR'] == '123.123.123.123')
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}

I basically want the same affect as putting that at the top of every script without actually doing that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Put it in its own file and set the auto_prepend_file configuration in the php.ini / .htaccess file to point to it.

Update: Since you mentioned lighttpd in a comment, note that you can configure it like this in the global INI file with PHP 5.3:

[PATH=/vhost/domain.com]  
auto_prepend_file = /vhost/domain.com/foo.php

[HOST=domain.com]
auto_prepend_file = /vhost/domain.com/foo.php

Or you can create the file /vhost/domain.com/.user.ini and do the same:

auto_prepend_file = /vhost/domain.com/foo.php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...