Trying to make PHP redirect work with PHP echo

Discussion in 'PHP' started by jimmack, Jan 20, 2011.

  1. #1
    Can anyone help me with this problem I am trying to make a php redirect work from a config file.

    Here is the part of the config file that I need a url redirect done in:

    $config['my_url'] = ' the redirect url would go here so I need to know how to config it';

    And here is the code I was working with to make the redirect work in the php pages.

    <?php echo $config['my_url'];?> ( was wanting to use this in the header of the index or built pages to call up the config file wich wold bring up the redirect path.
     
    jimmack, Jan 20, 2011 IP
  2. OnurSQL

    OnurSQL Guest

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Redirects must be sent before echo'ing out anything and like this
    header("Location: http://www.google.com");
    exit;
     
    OnurSQL, Jan 20, 2011 IP
  3. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #3
    or in echo use :
    echo '<script>window.location = "http://www.google.com";</script";
     
    tvoodoo, Jan 20, 2011 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    Which won't work for those with JS disabled. If you're going to use HTML you may as well use a meta redirect.

    Onur is right, unless you enable output buffering.
     
    Alex Roxon, Jan 21, 2011 IP
  5. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #5
    if your doing a echo
    why not echo a meta redirect and then you can set a timer on it so that they can read what your echo states in the first place.
     
    lowridertj, Jan 21, 2011 IP