Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Redirect after execution

Redirect after execution

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpcomquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cryptoknight17
    wrote on last edited by
    #1

    I've tried putting

    header('Location: http://www.google.com/');

    at the end of one of my scripts, but it won't redirect. If It's just

    < ?php
    header('Location: http://www.google.com/');
    ?>

    it works fine. I need to be able to run some stuff before it redirects the page.

    F J 2 Replies Last reply
    0
    • C cryptoknight17

      I've tried putting

      header('Location: http://www.google.com/');

      at the end of one of my scripts, but it won't redirect. If It's just

      < ?php
      header('Location: http://www.google.com/');
      ?>

      it works fine. I need to be able to run some stuff before it redirects the page.

      F Offline
      F Offline
      fly904
      wrote on last edited by
      #2

      In the PHP documentation[^] it actually quotes:

      php.net wrote:

      Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

      Two solutions:

      1. Have it (the header) at the top of the page before you output anything to the browser.
      2. Use Output Buffering[^] to hold the output before it is sent to the browser.

      If at first you don't succeed, you're not Chuck Norris.

      C 1 Reply Last reply
      0
      • F fly904

        In the PHP documentation[^] it actually quotes:

        php.net wrote:

        Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

        Two solutions:

        1. Have it (the header) at the top of the page before you output anything to the browser.
        2. Use Output Buffering[^] to hold the output before it is sent to the browser.

        If at first you don't succeed, you're not Chuck Norris.

        C Offline
        C Offline
        cjoki
        wrote on last edited by
        #3

        One other option is to echo a document.write to add a javascript redirect..its a bit of a hack, but works....provided someone does not turn off js in their browser.

        1 Reply Last reply
        0
        • C cryptoknight17

          I've tried putting

          header('Location: http://www.google.com/');

          at the end of one of my scripts, but it won't redirect. If It's just

          < ?php
          header('Location: http://www.google.com/');
          ?>

          it works fine. I need to be able to run some stuff before it redirects the page.

          J Offline
          J Offline
          jaypatel512
          wrote on last edited by
          #4

          You can run stuffs before that but make sure you dont echo anything else before giving this redirect. For e.g. validation of usernames, or anything which should be done before any HTML tags or echo is done.. - Jay.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups