SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $SERVER['SCRIPT_NAME'] For PHP CGI

    Hi guys,

    When using $SERVER['SCRIPT_NAME'] for PHP Apache Handler,it will output /phpinfo.php (for example) but whereas if it is PHP CGI, it will output php.cgi

    Is there a way to get $SERVER['SCRIPT_NAME'] for PHP CGI?

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Location
    Tucson, Arizona
    Posts
    1,858
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can try using a combination of __FILE__ and basename(), but it's hard to tell you what to look for without knowing exactly what you want.

  3. #3
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's working just fine here, when tested with PHP as CGI.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  4. #4
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $file_name = basename($_SERVER['SCRIPT_NAME']) . "php";

    Should strip the .cgi and append .php to the filename

    Thus go.cgi would be converted to go.php
    intragenesis, llc professional web & graphic design

  5. #5
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shouldn't have a .cgi at all. SCRIPT_NAME is taken from the exact URI after the domain name. So if it is www.example.com/phpinfo.php, SCRIPT_NAME will be /phpinfo.php.

    In fact, I think SCRIPT_NAME is taken right from the request. For instance, if the request starts with:

    Code:
    GET /phpinfo.php HTTP/1.1
    Host: www.example.com
    SCRIPT_NAME should be taken right out of the second part of that first line.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  6. #6
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry guys if my post is unclear. But apparently dreamhost have a CGI error when I point a form action to $_SERVER['SCRIPT_NAME'].
    Warning: Unexpected character in input: '' (ASCII=15) state=1 in /usr/local/dh/cgi-system/php.cgi on line 1240

    Parse error: syntax error, unexpected T_STRING in /usr/local/dh/cgi-system/php.cgi on line 1240

  7. #7
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should probably contact Dreamhost about that error, then, since it sounds like there is some problem on their end.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ascii 15 is a non printable control character(you cant see it), it means "shift out". i dont know what that character is actually used for, but it shouldnt be in your script.

    consider deleting and retyping that line.

  9. #9
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    beacuse in the form action, i put action="<?php $_SERVER['SCRIPT_NAME']; ?>" and this it will point to cgi-system/php.cgi instead of index.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •