Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts

    header location not redirecting

    PHP Code:
    <?php 

    include('config.php');
    if (isset(
    $_POST['submit']))
    {
    $username$_POST['username'];
    $password$_POST['password'];
    $myusername mysql_real_escape_string($username);
    $mypassword mysql_real_escape_string($password);  
    $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
    $resultmysql_query($sql) or die(mysql_error());

     
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($row mysql_fetch_array($result)) {
    $userid $_SESSION['id'] = $row['id'];    
    $username $_SESSION['username'] = $row['username'];  
    echo 
    $userid;
    echo 
    $username;
    header("Location: welcome.php");
    }
    else{
    echo 
    "Wrong username or password.";

    }


    }

    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    PHP Code:
    echo $userid;
    echo 
    $username;
    header("Location: welcome.php"); 
    Check http://php.net/header
    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. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
    You need to remove/comment echo statements above call to header().
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    include('config.php'); 
    if (isset(
    $_POST['submit'])) 

    $username$_POST['username']; 
    $password$_POST['password']; 
    $myusername mysql_real_escape_string($username); 
    $mypassword mysql_real_escape_string($password);   
    $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'"
    $resultmysql_query($sql) or die(mysql_error()); 

      
    // If result matched $myusername and $mypassword, table row must be 1 row 
    if($row mysql_fetch_array($result)) { 
    $userid $_SESSION['id'] = $row['id'];     
    $username $_SESSION['username'] = $row['username'];   
    header("Location: welcome.php"); 

    else{ 
    echo 
    "Wrong username or password."




    }
    ?>
    Login still doesn't work.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    How many more threads do you plan on opening for this issue? This is the second one I've closed that's pretty much all tied into your first.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •