SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: PHP_SELF

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I've got this piece of code that gets an ID from a database then submits it to the next page.

    In the code i use <?php echo $PHP_SELF; ?> however, since the function is in a different file from the one that needs to be submitted the action is blank.

    However, it may be just Internet Explorer 5 but it seams to submit to itself which makes everything easier.

    Is this just a bug in IE or will it work in Every browser. Is there an alternative to PHP_SELF so I can see if that will work or not.

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Apr 2001
    Location
    The Netherlands
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $PHP_SELF always points to the script you're currently executing, if you don't want that replace it with the script you want to send it to. for example <form action="part2.php">
    Did that sound biased?

  3. #3
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem you're having is that $PHP_SELF needs to be declared global in functions if it is used inside a function..

    PHP Code:
    <?

    function test_fn() {
       echo 
    "in test_fn<br>\n";
       echo 
    "php_self is $PHP_SELF<br>\n"
       echo 
    "exiting test_fn<br><br>\n";
    }
      
    function 
    test_fn2() {
       global 
    $PHP_SELF;
       echo 
    "in test_fn2<br>\n";
       echo 
    "php_self is $PHP_SELF<br>\n";
       echo 
    "exiting test_fn2<br><br>\n";

      

    echo 
    "php_self is $PHP_SELF<br><br>\n";
    test_fn();
    test_fn2();
      
    ?>
    In test_fn(), $PHP_SELF is blank, whereas in test_fn2(), $PHP_SELF has the correct value.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    followup:

    Leaving a from action balnk will default to the current page in IE, however in Netscape you will get a 404 error. Netscape does not handle these blank actions quite the same as IE. I would suggest always making sure the form action has a valid page in it.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually use $HTTP_SERVER_VARS["PHP_SELF"];

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Freddy and Cokeman, thanks for your replies. The global did the trick very nicely and works correctly now. Freddy, thanks for that piece of info, I had a hunch that netscape would do something like that.

    GoD, Thanks for that alternate of PHP_SELF, it may be the same almost, but I may use it someday.

    Again, thanks for your help everyone,
    Peter

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think mine uses global also but in a different way


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
  •