SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: $php_self

  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $php_self

    Hi, I learned at Kevin's tut to use $PHP_SELF in a form as "action" to be redirected to the same page.
    For example like this :

    PHP Code:
    if $submit:

     
    put the staff in the db

    else : 
      <
    form action=$PHP_SELF>
        
    show the form
      
    </form>
    endif: 
    Now I recognized that it also worked fine without the "$PHP_SELF", I just left the action field blank. Now my project is online and people report me that when they click submit nothing happens, they just see the blank form again. Can there be any correlation and if so why does it work on my computer ? ( one told me it worked one time out of 6 ) So what's going on here. Please help me, it's urgent.

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remeber it needs to be in <?php ?> tags - I personally recommend using basename($PHP_SELF) instead as it saves you getting nasty paths incorporating your PHP cgi on some installs of PHP:

    <form action="<?php echo basename($PHP_SELF); ?>">

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But I'm still not sure if this is the problem, and I can not test it as it works fine when I do it. Anyway why do you nead $PHP_SELF or basename($PHP_SELF) when it also works without.
    By the way, I'm using FastTemplates, is it just fine to have the form in a template like this
    <form action='{ACTION}'>
    ....
    and than parse "basename($PHP_SELF)" to the template into {ACTION} ?

  4. #4
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work just fin with fastTemplate if you do that. You should include an action for the form because although Internet Explorer defaults to usign the current page as the ACTION of the form other browsers may not do this.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, just once again . As far as I know, for my PHP Skripts it doesn't matter:
    - which Browser the user has
    - if he is using a firewall etc.
    - if he is using the Internet via an Intranet ( like in a company ) etc.
    Is it correct? Because I still don't know why the skript didn't work in some cases but without any problems on my Computer ( and many others ).

  6. #6
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah thats correct but the way you are calling your scripts may vary..

    lets say i use $PHP_SELF than if you look at the source it will say:

    action="filename.php"

    or even

    action="directory/filename.php"

    If you don't use $PHPSELF and just type nothing then in the source (browser source) it will say

    action=""

    While IE presumes that the action is directed to the file itself other browsers may not..

    So the script is working fine but if you don't send the variables because the browsers thinks action = none or only refresh the page won't be loaded correctly..

    So if you don't want to depend on browsers use an action.


    Greets

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun

  7. #7
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, me again. They just told me which pages worked and which not. Now it's funny, but those pages without $PHP_SELF ( without any "action" in the form tag ) worked and those with a correct action did not work ( they just saw the blank form again )
    That's strange, isn't it? Any idea.

  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)
    One thing to keep in mind is that IE will default to the same page if the action is omitted. Netscape will die.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •