header("Location: http

Discussion in 'PHP' started by newlearn, Apr 4, 2007.

  1. #1
    I have a PHP code and that works fine on localhost on my laptop.
    The configuration is - Apache 2. PHP 4.4.5


    But when I try to make it work on the hosting site, it does not.
    The page doe snot get redirected.
    header("Location: http://www.xxx.com/");

    I have tried different ways to redirect the form but nothing works. Is there something with the php.ini settings?
     
    newlearn, Apr 4, 2007 IP
  2. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Ensure that your start php tag are the first item in the script:

    For example

    line 1 <?
    line 2 header("Location: http://www.xxx.com/");
    line 3 exit();
    line 4 ?>

    NOT

    line 1
    line 2 <?
    line 3 header("Location: http://www.xxx.com/");
    line 4 exit();
    line 5 ?>
     
    datropics, Apr 4, 2007 IP
  3. degy

    degy Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    did you try with meta tag? Or is it neccesery for you to use header?
     
    degy, Apr 4, 2007 IP
  4. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    What exactly does it do? Does it show some error message?
     
    Houdas, Apr 4, 2007 IP
  5. newlearn

    newlearn Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $sql = "SELECT * FROM user WHERE
            userid = '$uid' AND password = '$pwd'";
    		
    $result = mysql_query($sql);
    
    if (!$result) {
      error('A database error occurred while checking your '.
            'login details.\\nIf this error persists, please '.
            'contact you@example.com.');
    		
    exit ;}
    
    
    
    if (mysql_num_rows($result) == 0) {
      unset($_SESSION['uid']);
      unset($_SESSION['pwd']);  
      ?>
    
      <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title> Access Denied </title>
        <meta http-equiv="Content-Type"
          content="text/html; charset=iso-8859-1" />
      </head>
      <body>
      <h1> Access Denied </h1>
      <p> Your user ID or password is incorrect, or you are not a
         registered user on this site. To try logging in again, click
         <a href="<?=$_SERVER['PHP_SELF']?>">here</a>. To register, click <a href="signup.php">here</a>.</p>
      </body>
      </html>
      <?php
      exit;
    }
    [B]
    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'location.php';
    header("Location: http://$host$uri/$extra");
    [/B]
    ?>
    
    Code (markup):
    I have the code like this, redirecting is on conditional basis.
     
    newlearn, Apr 4, 2007 IP
  6. newlearn

    newlearn Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am not too good with web developement.

    But how can I use meta tags on conditional basis. I should split the form and then use meta tags in one form?
     
    newlearn, Apr 4, 2007 IP
  7. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Try echo the address variables so you can make sure they are set properly. Also combine them before you put them into the location: bit.
     
    mad4, Apr 4, 2007 IP
  8. newlearn

    newlearn Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    No error messages although I have error_reporting ON.

    And it works on my PC running on windows XP and not on the hosting site.
     
    newlearn, Apr 4, 2007 IP
  9. degy

    degy Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    sure just use

    if (condition) echo'<meta http-equiv="refresh" content="0;url=http://www.******.com'">';
     
    degy, Apr 4, 2007 IP
  10. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #10
    degy is correct - you could use that. The main reason why the header would not work is if you are OUTPUTTING information to the user screen already (this could be a blank space) Check to make sure that is not the case. Also, echo the values of the http:// address in the header function, make sure it is not blank.
     
    datropics, Apr 4, 2007 IP
  11. newlearn

    newlearn Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11

    Thanks. It is able to redirect now. But I have another problem . It does not take the session value.

    I have stored uid in session.
    $_SESSION['uid'] = $uid;

    and trying to echo $_SESSION['uid'] after redirecting t another page.
    I have session_start() at the start of the page.
     
    newlearn, Apr 4, 2007 IP
  12. newlearn

    newlearn Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I did check (displayed) the address and other details in the header and as I see everything is correct
     
    newlearn, Apr 4, 2007 IP
  13. degy

    degy Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    try

    if(isset($_SESSION["status"]))
    {
    }else{
    session_start();
    $_SESSION["status"]=1;

    }


    so you'll only start new session if session doesn't exist
     
    degy, Apr 4, 2007 IP
  14. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    mention

    error_reporting(0);

    at first line of file

    and remove white spaces from included files.
     
    jitesh, Apr 5, 2007 IP