How to Redirect page?

Discussion in 'PHP' started by Devprakash, Jan 29, 2007.

  1. #1
    H! to all members of DP
    if path and id is'nt valid then
    how to redirect a page to index.php



    <?php
    echo "<br>";
    if ($_GET['id'])
    {
    $id = $_GET['id'];
    }
    else
    {
    die ("No ID Selected");
    }

    echo "<body bgcolor='#ffffff'>";
    echo "<table border='0' bgcolor='ffffff'>";
    echo "<tr><td>";
    echo "<tr><td>";
    echo "<tr><title> $site</title><td>";
    echo "<tr><td>";
    echo "<img src='./$path" . $id . "'>";
    ?>

    tell me wht i've to put here to redirect user to index.php

    :- sorry for my bad grammar
     
    Devprakash, Jan 29, 2007 IP
  2. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Use the header function.

    header("Location: index.php");
    PHP:
     
    chopsticks, Jan 29, 2007 IP
  3. Devprakash

    Devprakash Well-Known Member

    Messages:
    338
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    120
    #3


    not working plz suggest another.
     
    Devprakash, Jan 29, 2007 IP
  4. beermaker74

    beermaker74 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    here is a bit of code i put to double check if a user is logged in

    if (!isset($_SESSION['username'])){
    header("Location: login.php");
    }

    the header works everytime for me. Are you getting headers already sent error? if thats the case you need your redirect towards the top of the page.
     
    beermaker74, Jan 29, 2007 IP
  5. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try this:
    <?php
    # take away this <br>
    # echo "<br>";
    if ($_GET['id'])
    {
    $id = $_GET['id'];
    }
    else
    {
    # I guess you want to redirect here
    header("Location: http://www.mydomain.com/redirect_page");
    #die ("No ID Selected");
    }
    
    ...
    
    ?>
    PHP:
    HTH, cheers
     
    picouli, Jan 29, 2007 IP
  6. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #6
    It doesn't work because you have "echo "<br>";" before it. For the header function to work with that redirect you need to have no html outputted prior to it being used.
     
    chopsticks, Jan 30, 2007 IP
  7. Devprakash

    Devprakash Well-Known Member

    Messages:
    338
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    120
    #7
    thanx for suggestion.
     
    Devprakash, Jan 30, 2007 IP