SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Help $PHP_SELF

  1. #1
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly does the variable $PHP_SELF do?

    I have a script (located in my root directory) that uses the variable $PHP_SELF as the "action" of the form. For some reason the url in the browser will then point to "http://domain.com/php/php/script.php". Why does this happen and how can I change it?

    Also, when you have your mouse over a link, the url at the bottom left side of the browser says "http://domain.com/php/php/script.php?action=show_list& category_id=006". Why is there all those spaces? When you click on the link the url in the browser reads "http://domain.com/php/php/script.php?action=show_list&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20category_id=006".

    Hopefully someone can figure out what is happening and knows how to fix it.

    Thanks,

    -JRW

  2. #2
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I just got a response from most host saying, "Yeah... that will happen on our PHP implementation. Don't use $PHP_SELF. Use $REQUEST_URI perhaps... ."

    Is this normal and how can I fix this?

    Thanks again,

    -JRW

  3. #3
    SitePoint Enthusiast ericd's Avatar
    Join Date
    Nov 2000
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im not 100% sure, but i presume it something to do with the httpd.conf file,, but dont quote me on that, its just a thought, is the PHP on windows?

    anyway

    try using

    $SERVER_NAME$REQUEST_URI

    in your form action

    see if this does the job

  4. #4
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have had problems using $PHP_SELF with Netscape while serving the page with Apache for win32 on lcoalhost (127.0.0.1). I'm not sure how it would work if the site was hosted but for the meantime I call the page itself insted for using $PHP_SELF. I know this may be a maintenance nightmere but it functions consistently on both IE and Netscape.

  5. #5
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I have fixed both problems thanks to my host and SitePoint members. The first problem with $PHP_SELF was due to my hosting services configuration of PHP. I used $REQUEST_URI in its place adn everything seems to work just fine. Not too sure why there are 2 variables that do the exact same thing.... but oh well.

    The problem with all the extra %20's in the URL was due to a few extra spaces in some code. This must have happened due to all the cutting and pasting that has been done.

    Peter at Aplushosting has been very good about helping me and taking care of all my problems.

    Also, thanks for all the replys,

    -JRW

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by sstaubin01
    I have had problems using $PHP_SELF with Netscape ...
    It is erroneous to say that you have a problem with PHP and a browser (NS, IE, etc). PHP is executed on the server. Your browser (should) never see the php code in your scripts. All the browser receives is plain 'ol HTML. So if you are having issues with a browser then your PHP code is probably generating bad HTML.

    There was a recent thread discussing a common mistake in using $PHP_SELF - not including it in the namespace within a function.

    eg:
    Code:
    function foo() {
    	echo "<a href='$PHP_SELF?foo=bar'>foo bar</a>";
    }
    will generate the following HTML
    Code:
    <a href='?foo=bar'>foo bar</a>
    Note how $PHP_SELF evaluated to "" creating the erroneous URL ?foo=bar

    This is because the global $PHP_SELF was not in the scope of function foo(). NS and IE will handle this erroneous code differently. NS will do nothing when the hyperlink is clicked, while IE will interpret it as a self reference.

    However,
    Code:
    function foo() {
    	global $PHP_SELF;
    	echo "<a href='$PHP_SELF?foo=bar'>foo bar</a>";
    }
    Will generate the following HTML
    Code:
    <a href='self.php?foo=bar'>foo bar</a>
    So the issue is that for some reason the value of $PHP_SELF is not being set correctly.
    Last edited by freakysid; Feb 10, 2001 at 19:54.

  7. #7
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's been some time since I had this problem and I've been going with the solution of coding the page it self instead of using $PHP_SELF. I do remember thinking the problem was how Apache for WIN32 was handling $PHP_SELF. I didn't notice any problems with EI but I assumed EI may have ignored the code returned and re-served the page.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem will only appear when running PHP in cgi mode. Because the script is run through the php.exe interpeter and so $PHP_self will be set to the location of the interpreter then the name of the script. Solution like stated above, use $PATH_INFO or $REQUEST_URI, or demand a server module from your host.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Addict certify's Avatar
    Join Date
    May 2001
    Location
    Malaysia
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to bring back old topic but I'm on a dedicated server so I can change the php config in my server. I have this problem after I upgrade to PHP 4.1.0. Previously all $PHP_SELF is working fine, where and how do I change the settings so the $PHP_SELF can work again?

    Please help.
    Your WebHosting Partner - RouterWebHost.com
    eXam SIMulation Software - ExamSim.net
    geeks forums -ProgrammingTutor.com
    BMWClub of Malaysia - BMWClub.com.my
    unofficial MU Fan Club coming soon - ManchesterUnited.com.my


  10. #10
    SitePoint Addict certify's Avatar
    Join Date
    May 2001
    Location
    Malaysia
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.certifyexpress.com/forum/usercp.php?urloverride=1&prevpage=www.certifyexpress.com%2Fphpresume%2Findex.php

    My browser is adding %2F in between and therefore it won't redirect back to the original page.
    Last edited by certify; Feb 14, 2002 at 05:52.
    Your WebHosting Partner - RouterWebHost.com
    eXam SIMulation Software - ExamSim.net
    geeks forums -ProgrammingTutor.com
    BMWClub of Malaysia - BMWClub.com.my
    unofficial MU Fan Club coming soon - ManchesterUnited.com.my



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
  •