$_server[script_name]"


#1

Hello,

I am trying to install PHP script. During installation it detects the whole URL using:

def_exp => '$str = “http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘SCRIPT_NAME’];

HOWEVER, for some reason the URL it detects is my___domain.com/cgi-system/php.cgi

which is not true because it suppose to show ONLY my__domain.com/

It seems that $_SERVER[‘SCRIPT_NAME’ is responsible for this, is there any way to fix it? I am concerned about this because $_SERVER[‘SCRIPT_NAME’ is used throughout the whole script system.

Is there a way to change it or something?


#2

I had a similar problem with a script I was using, I think the problem stems from the fact that PHP is running as CGI.

Try using this line instead;

def_exp => '$str = “http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘SCRIPT_URL’];

or perhaps…

def_exp => '$str = $_SERVER[‘SCRIPT_URI’];

Mark


Save [color=#CC0000]$50[/color] on DreamHost hosting using promo code [color=#CC0000]PRICESLASH[/color] ( Click for promo code details )


#3

That is a normal result of running PHP as CGI instead of mod_PHP. There are a couple of workarounds I can suggest; which works best for you depends a lot on your script.

  1. Add this following assignment to your script:
    $_SERVER[‘SCRIPT_NAME’] = $_SERVER[‘SCRIPT_URL’];

** or **

  1. Run the script under mod_php, by inserting:
    “AddType application/x-httpd-php .foo” or
    “AddHandler application/x-httpd-php .php“ in your .htaccess file.

You can get an idea of other potential workarounds by running creating a file called phpinfo.php, in a web-accessible directory, containing the following:

<?php phpinfo(); ?>

and then browsing to that file and inspecting the output to see what other environment variables your script uses that might be affected. You can handle them the same way by just reassigning the value to one that has the value you need when running PHP-CGI. Good Luck, and Merry Christmas!

–rlparker


#4

[quote]1) Add this following assignment to your script:
$_SERVER[‘SCRIPT_NAME’] = $_SERVER[‘SCRIPT_URL’];[/quote]
This suggestion from rlparker is probably the best way, since it will save you from having to go through the entire script changing every occurrence of SCRIPT_NAME.

Mark


Save [color=#CC0000]$50[/color] on DreamHost hosting using promo code [color=#CC0000]PRICESLASH[/color] ( Click for promo code details )