How to use refresh and location?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fruityfreak
    New Member
    • Jun 2007
    • 24

    #1

    How to use refresh and location?

    I've got problem using

    header('Refresh : 2; login.php');

    i understand the concept behind it just that it can't work on my system.

    can anyone help me solve my problem.

    my error message is the following:


    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \fyp\do_login.p hp:60) in C:\xampp\htdocs \fyp\do_login.p hp on line 67
    Sorry! Your username/password is incorrect.
    Please try again.

    You'll be redirected back to the login.


    that page coding is something like this
    [code=php]<?php
    //Starting a session
    session_start() ;

    //NOTE: START SESSION BEFORE USING require()
    require('db.php ');

    //Retrieve and password from form
    $uname = $_POST['username'];
    $pwd = MD5($_POST['pwd']);

    //Connect to database server and choose database:
    mysql_connect(M ACHINE, USER,'');
    mysql_select_db (DBNAME);

    //Query to retrieve records from users table
    $sql = "select * from users where username='".$un ame."' AND password='".$pw d."'";

    //Executing query...storing records in $result
    $result = mysql_query($sq l);

    if(mysql_num_ro ws($result) == 1){ //valid user
    /*test*/
    //echo "Your username and password are correct.";
    //Saving info in session: no need to save password, but only testing!
    $_SESSION['username'] = $uname;
    $_SESSION['pwd'] = $pwd;
    $_SESSION['login'] = 1;
    $row = mysql_fetch_arr ay($result);
    $role = $row['admin'];
    if($role ==1){
    $_SESSION['role'] ="admin";
    }//role =admin
    else if ($role ==2){
    $_SESSION['role'] ="manager";
    }//role = non-admin
    else{
    $_SESSION['role'] ="staff";
    }//role = non-admin

    $_SESSION['userid'] = $row['userid'];

    //Display link to index.php
    echo header('locatio n: index.php');

    }
    else {
    $_SESSION['login'] = 0;
    }
    ?>
    <html>
    <head>
    <link rel="stylesheet " type="text/css" href="fyp.css" />
    </head>
    <body>
    <div id="header">
    </div>

    <div id="leftcol">
    <?php
    echo "<br><a href = login.php>Log In</a>";
    ?>
    </div>

    <div id="maincol">
    <?php
    header('Refresh : 2; login.php');

    echo "Sorry! Your username/password is incorrect.<br>" ;
    echo "Please try again.<br><br>" ;

    echo "You'll be redirected back to the login.";
    ?>
    </div>
    </body>
    </html>[/code]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, fruityfreak.

    Take a look at this thread.

    Comment

    Working...