Meta Refresh does not pass on PHP variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PHPstarter
    New Member
    • Jun 2009
    • 77

    Meta Refresh does not pass on PHP variable?

    I'm trying to get a meta redirect to pass on a php variable to the redirected page, using the $_GET method.

    I have the mypage.php?user =created&userna me=$name&commen t=$comment etc

    , but ONLY the first 'user=created' seems to be passed on.

    All the other in line, like the username=$name comes from a script where this meta refresh is used, at the bottom.
    The script uses sessions, but it never sends the other variables.
    Not the original or simple test variables.

    The variables does echo during the script, so it must be the meta refresh that are stopping them.

    Is this a common problem, or can I fix this somehow?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    hard to tell without something to look at.

    Comment

    • PHPstarter
      New Member
      • Jun 2009
      • 77

      #3
      I thought this could be a standard issue, but here is the script stuff:

      Code:
      		echo "<meta http-equiv='Refresh' content='1;url=mypage.php?user=created&username=$name&password=$pw2&comment=$comment&accesslevel=$accesslevel#msg'> ";

      all variables are defined like: $comment=$_POST["comment"];
      Everything is sent from a submit form on the same page returning to via the meta refresh.
      The URL dont even have the variables filled, so it seems like the meta refresh stops php or something.

      Using a different method where i would use $url and echo $url; inside the meta refresh area didnt work. The browser simply said that $url was not found, even though it was defined as a whole url above the meta refresh :/

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        The URL dont even have the variables filled, so it seems like the meta refresh stops php or something.
        due to PHP being a server side language, it has finished working before the HTML is sent to the browser.

        what does the meta tag in the HTML look like? (increase the refresh delay sufficiently)

        Comment

        • PHPstarter
          New Member
          • Jun 2009
          • 77

          #5
          In the sourcecode during the script, it looks like this:

          <meta http-equiv='Refresh' content='10;url =mypage.php?use r=created&usern ame=bob&passwor d=bobpw&comment =bobcmt&accessl evel=2#msg'>


          So believe it or not, the whole thing actually worked when I increased the refresh delay from 1 to 10.
          Does the script need more time than 1 second perhaps? Sounds so strange.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            as I already mentioned, the script usually finishes first, before sending the output.

            Comment

            • PHPstarter
              New Member
              • Jun 2009
              • 77

              #7
              I guess we can say it is working, it just needed 2 seconds to work it seems.

              Anyway thanks for the help!
              I wouldn't have discovered it if you didn't tell me to increase the refresh delay =)

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                why do you need the refresh anyway? you could instantly forward using header("Locatio n: $url").

                Comment

                • PHPstarter
                  New Member
                  • Jun 2009
                  • 77

                  #9
                  Got a header error :p

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    this may well be if you’ve never worked with headers before.

                    Comment

                    • PHPstarter
                      New Member
                      • Jun 2009
                      • 77

                      #11
                      I have them lots of places, but I'm not familiar with the technical reasons for the errors themselves, though I've had them before (the errors).

                      I heard whitespace could be a cause for this error, but in this case it looks fairly implausible.

                      Comment

                      • rudiedirkx
                        New Member
                        • Jan 2010
                        • 7

                        #12
                        Your header() probably throws a warning (not an error) because there was already output from the PHP script. Since HTTP headers (that's what it is) must be outputed before any other content, the header command must be given before any output command (like echo/print).
                        Whitespace is indeed a possibility. Why is that so implausible? Also possible is you just echo'ed something already. You can see that in your HTML (especially then the delay is 10 sec).

                        Also, I don't believe it matters whether the delay is 0, 1, 2 or 10 seconds. PHP doesn't care about that value. The correct HTML should be printed whatever the HTML is.

                        Try this (it's neater, if nothing else):
                        Code:
                        echo '<meta http-equiv="refresh" content="1;url=mypage.php?user=created&amp;username='.$_POST['name'].'&amp;password='.$_POST['pw2'].'&amp;comment='.$_POST['comment'].'&accesslevel='.$_POST['accesslevel'].'#msg" />';

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          See this unfinished article.

                          Comment

                          Working...