<? echo $PHP_SELF;?> loads different page on submit form

Discussion in 'PHP' started by jacka, Jan 10, 2008.

  1. #1
    Hi

    I have a form with a php code in it that works fine on apple mac osx, using <? echo $PHP_SELF;?> it refreshes and loads the same page.
    However when I test it on windows xp, it opens default xx.com/php.index page instead.
    I am using apache server, by the way.

    Any help is much appreciated.
    :confused::confused:
     
    jacka, Jan 10, 2008 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    For some reason, I want to say that needs to be:

    <? echo $_SERVER['PHP_SELF']; ?>

    and I think the reason is a change in PHP from v4 to v5.


    edit: of course if you are including that page in another that is the page that will be refreshed (the main, not the included).
     
    Colbyt, Jan 10, 2008 IP
  3. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi
    Spot on. correctomondo!!!

    Many thanks.
    I suppose that teaches me never to cut corners.
    :D
     
    jacka, Jan 10, 2008 IP
  4. Kieran.in

    Kieran.in Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah, the reason it worked on your Apple was probabally due to global variables.
     
    Kieran.in, Jan 10, 2008 IP
  5. ausome

    ausome Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Just another thing to watch out for is using shortened PHP Tags like you have.

    <? echo $_SERVER['PHP_SELF']; ?>

    Some servers need the full deal

    <?php echo $_SERVER['PHP_SELF']; ?>

    But you'll know if that happens.

    You can also use

    <?=$_SERVER['PHP_SELF']?>

    which works on some servers as well.

    To be safe it's best to use the longer format.

    Just my 2 cents worth.

    Cheers
    Tim
     
    ausome, Jan 11, 2008 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    '<?=' will work as a replacement for '<?php echo ' anywhere short tags are enabled. I always use the long tags... I believe it's easier to just expect that short tags is disabled.
     
    TwistMyArm, Jan 11, 2008 IP