SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP_SELF not behaving for me.

    I put together a page with a form in with the following code:

    PHP Code:
    <form action="<?php echo($PHP_SELF); ?>" method=post>
    I then moved the page out of the root directory of the server into a folder called 'admin '. now the target of the form is coming up as '/admin/thepage.php/admin'. Can anyone tell me how to avoid the extra '/admin' that has tagged on the end of the action?

  2. #2
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No. It sounds like a problem at your server, but I don't know what platform or software you use.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  3. #3
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am running windows 9x with a xitami server. I am working around the problem by putting password and username authentication in the php but it would have been nicer to just protect the directory. Any suggestions for future reference will still be appreciated though.

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use basename().

  5. #5
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?echo($PHP_SELF ."<br />");  echo(basename($PHP_SELF))?>
    results in

    /directory/file.php/directory<br />directory
    being outputted - it is as if it thinks the directory is the file (?)

  6. #6
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is crazy

  7. #7
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok get this - I added more directories to see what would happen. My test page is now
    PHP Code:
    <?echo($PHP_SELF ."<br />");  echo(basename($PHP_SELF)."<br />"); echo(dirname($PHP_SELF)."<br />");?>
    I navigate to http://localhost/directory0/directory1/directory2/tester.php

    and get this result

    /directory0/directory1/directory2/tester.php/directory0/directory1/directory2 <br /> directory2 <br /> /directory0/directory1/directory2/tester.php/directory0/directory1 <br />
    !!!!!!!!!!

  8. #8
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would check your server config for something that appends the directory to all scripts.

  9. #9
    SitePoint Guru DenverDave's Avatar
    Join Date
    Feb 2001
    Location
    Denver, Colorado
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep $PHP_Self does not work correctly (or at least the way it does on UNIX) on Windows PC's.

    Basename() might work mentioned above or I include the following code in every Script (or include file if there is on) for Windows Applications that have $PHP_SELF. Then I don't have to rewrite the open source code for Windows:

    // Fix PHP_SELF for Windows
    $PHP_SELF = $PATH_INFO;

    I think their is some justification for why this is happening, but the bottom line is the code needs to be adjusted. I was very surprised when I found this also and it is amazing that PHP does not have the adjustment made automatically. Seems like PHP4 should run the same way on every platform.

    Dave

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dave the reason behind that, is most people run PHP in CGI mode on Windows platforms, where the code has to be passed trhough the interpreter. So $PHP_SELF will satrt from the path of the interpreter, usually C:\php\php.exe, abd links start turning out like

    php.exe/admin/index.php


    And your solution will work fine, I have used it before. But for a more permanent fix try using PHP as server API either through IIS using the php4isapi.dll or through apache using the php4apache.dll
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Guru DenverDave's Avatar
    Join Date
    Feb 2001
    Location
    Denver, Colorado
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - I copied your explanation off (with credit) for the next time that I have to explain this.

    But why (don't you hate whys) does PHP4 not make the $PHP_SELF for us? Is there ever a situation for Windows in CGI mode that we would not want $PHP_SELF = $PATH_INFO; ???

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most likely not, what I have done in the past is to use the

    auto_prepend_file =

    in the php.ini file or in a .htaccess file to automatically prepend a file to every page in the site, so you can put

    <?
    $PHP_SELF = $PATH_INFO;
    ?>

    in it and it will be included in every php page of the site automatically, and when you move the site to linux if you choose to, no code will need to be changed since the auto_prepend_file directive won't be set on the server unless you set it for some reason.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the advice people - the problem remains though. This code:
    PHP Code:
    <? echo($PHP_SELF ."<br />");  echo(basename($PHP_SELF)."<br />"); echo(dirname($PHP_SELF)."<br />"); $PHP_SELF $PATH_INFO; echo($PHP_SELF ."<br />"); echo(basename($PHP_SELF)."<br />"); echo(dirname($PHP_SELF)."<br />"); ?>
    when I navigate to http://localhost/backup/01/tester.php results in this html:

    /backup/01/tester.php/backup/01 <br /> 01 <br /> /backup/01/tester.php/backup <br /> /backup/01 <br /> 01 <br /> /backup <br />
    now it appears to think the parent directory is the file.
    (sorry about the long lines, I am new to this forum and haven't figured out how to start a new line yet!)


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
  •