Results 1 to 15 of 15

Thread: header function

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    37

    header function

    It says in books etc that I shouldn't use header function after data has been sent to the client. What if I want to forward some info to another webpage after recieveing some of it from the user. How do I do it if I can't do it with the header function? or Can I?

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    you will have to setup a condition or function to do such, something along these lines:

    PHP Code:
    <?php
      
    if (isset($_REQUEST['url']))
        
    header("Location:".$_REQUEST['url']);
    ?>
    <form method="post" action="?">
    <input type="text" name="url" />
    <input type="submit" name="submit" value="Go!" />
    </form>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    you can use the meta tag refresh

    <META HTTP-EQUIV="Refresh" Content="5;URL=your site you want to goto.com">


    the 5 is how many seconds it will take.

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    you can use the meta tag refresh

    <META HTTP-EQUIV="Refresh" Content="5;URL=your site you want to goto.com">


    the 5 is how many seconds it will take.
    That wont really work for what he wants.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    actually you are right. headers won't work either

    What if I want to forward some info to another webpage after recieveing some of it from the user

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by phpman
    actually you are right. headers won't work either
    My code does what he asked. He takes information from the client and goes to to it as if it were a web address
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    so does this

    PHP Code:
    <?php
      
    if (isset($_REQUEST['url']))
        echo
    "<META HTTP-EQUIV=\"Refresh\" Content=\"5;URL=".$_REQUEST['url']."\">";
    ?>
    <form method="post" action="?">
    <input type="text" name="url" />
    <input type="submit" name="submit" value="Go!" />
    </form>

  8. #8
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by phpman
    so does this

    PHP Code:
    <?php
      
    if (isset($_REQUEST['url']))
        echo
    "<META HTTP-EQUIV=\"Refresh\" Content=\"5;URL=".$_REQUEST['url']."\">";
    ?>
    <form method="post" action="?">
    <input type="text" name="url" />
    <input type="submit" name="submit" value="Go!" />
    </form>
    Yes, but since he asked for a header function I gave an example of one.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  9. #9
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    correct. but he asked what to use if he couldn't use a header function. he will get an error if he sends data to the client and then send the header function. if he doesn't want that error than he can use the meta tag way.

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    correct. but he asked what to use if he couldn't use a header function. he will get an error if he sends data to the client and then send the header function. if he doesn't want that error than he can use the meta tag way.
    Matt's function works fine. He will not get an error with it and it is much more efficient.

    And he did ask what to do if he couldn't use it, but he also added "or can I?" and that's what Matt was answering. That he could. Which voided the first question.

    But I won't argue this thread anymore.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    if data has been sent to the client (outputed to the screen) he will get headers already sent error.

    that is why my function works better than Matt's.

    but whatever.

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Exactly where in Matt's example is there data output before the header function?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    no where but the question was

    It says in books etc that I shouldn't use header function after data has been sent to the client. What if I want to forward some info to another webpage after recieveing some of it from the user.

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Matt's script showed him how to fix that.

    Do we have to go round and round?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    37
    Sorry for not replying for so long.
    Thx for all the help. I finally got it working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width