1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php redirect() function

Discussion in 'PHP' started by nrodes, Oct 25, 2008.

  1. #1
    I am trying to make a group chat on my website. In this code I have it write to a html file then redirect the user to the page. When I run this it says:

    Fatal error: Call to undefined function redirect() in C:\Program Files\Abyss Web Server\htdocs\groupchat.php on line 18

    I can't figure out what's wrong.

    In /groupchat.php on line 18 it says redirect(/chat.htm);

    Can anyone help me?
     
    nrodes, Oct 25, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    function redirect($red) {
    header("Location: ".$red);
    }
    add that somewhere
     
    Kyosys, Oct 25, 2008 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Means no such function. Create yourself using Kyosys's
     
    ads2help, Oct 25, 2008 IP
  4. neran

    neran Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yep, no such function.
     
    neran, Oct 25, 2008 IP
  5. Calon

    Calon Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No such function, a header redirect as already exampled is the closest thing to what you're looking for, you can create a function named "redirect" with the code already given by Kyosys.
     
    Calon, Oct 25, 2008 IP
  6. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #6
    You might want to add exit; below the header() as well.
     
    crazyryan, Oct 25, 2008 IP
  7. Calon

    Calon Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Why?

    Header acts instantly, but it's required to be at the top of the page before any output is executed.
     
    Calon, Oct 25, 2008 IP
  8. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    because the script will continue running after you redirected.
     
    Kyosys, Oct 25, 2008 IP
  9. Calon

    Calon Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Didn't think of it that way.

    Thanks for pointing it out :)
     
    Calon, Oct 25, 2008 IP
  10. sources68

    sources68 Member

    Messages:
    74
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #10
    function redirect($link) {
    echo "<script language=Javascript>
    document.location.href='$link';
    </script>";
    }
     
    sources68, Jan 7, 2013 IP
  11. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #11
    php redirect is http://www.php.net/header

    header("Location: http://www.yoururl.com/yourpage.html");
    or
    header("Location: /yourpage.html");

    !
     
    EricBruggema, Jan 7, 2013 IP