Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Viper N
    Viper N's Avatar
    Guest

    <?PHP header(location)?>?

    Why does this not redirect users to another site?

    <?php


    $uname=htmlspecialchars($_POST['drivername']);
    $pword=htmlspecialchars($_POST['driverpassword']);

    $user_name='nreddin';
    $password='';
    $database='rides';
    $server='localhost';


    $conn=mysql_connect($server,$user_name);
    if(!$conn){
    die('No connect:'.mysql_error());
    }
    else{
    print"connected to server<br>";
    } //good so far

    $db=mysql_select_db($database, $conn);
    if(!$db){
    die('Database not found:'.mysql_error());
    }
    else{
    print"connected to database<br>";

    $SQL="SELECT*FROM login WHERE L1='$uname' AND L2='$pword' " ;
    if(!$SQL){
    die("Table not found".mysql_error());
    }
    else{
    print("Tabvle Selected");
    }

    $result=mysql_query($SQL);
    if(!$result){

    print(mysql_error()."<br> Improper Username and/ or Password! * NOTE all Characters are CaseSensitive*");
    }
    else{
    //print("fidskfj"); trouble shooting works this far with proper syntax closure

    $num_rows=mysql_num_rows($result);
    if($num_rows==1){
    session_start();
    $_SESSION['authenticated']="1";
    if(!(header("location:http://localhost:8888/welcomepg.htm"))){
    print(mysql_error());}
    else{print('header');}
    }
    else{
    $errorMessage='Invalid Login';
    session_start();
    $_SESSION['authenticated']='';
    }

    }
    }
    print($num_rows);
    // it knows it is logged in; Session start fucking it up//
    ?>

    The print num_rows was put there at the end just to help troubleshoot.
    The whole thing is a bit messy... sorry
    ANy help is appreciated...

  2. #2
    lansingstudent09101
    lansingstudent09101's Avatar
    Guest
    a browser can't DO anything with headers except the first time it receives them and it HAS to have them before it gets the first text.

    The first time you output text (print"connected to database<br>" the browser MUST send the headers.

    You should get an error message that says something in the order of "cannot send header; headers already sent". So either don't send text before you redirect, (no print, no echos) or be prepared for the redirect to fail anytime the script goes down a path that sends text.

 

 

Quick Reply Quick Reply

Click here to log in


What is the number after 87?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 12-19-2010, 04:54 AM
  2. Howcome in PHP, my Header("Location:") skips EVERYTHING?
    By livingwater8425 in forum Discuss PHP
    Replies: 0
    Last Post: 11-19-2010, 04:20 AM
  3. Replies: 1
    Last Post: 10-22-2010, 08:34 AM
  4. Replies: 0
    Last Post: 02-15-2010, 04:47 PM
  5. PHP header location help?
    By titchyc in forum Discuss PHP
    Replies: 0
    Last Post: 04-07-2009, 10:04 AM

Bookmarks

Posting Permissions

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