-1

EDIT: There are invisible spaces after the PHP tag. I removed them, and it's now working.

So I have this website project that was built for 4 weeks. THE LOGIN FORM HERE IS WORKING.

This is the code for the login.php

<?php
 session_start(); // Starting Session
 $error=''; 

 if (isset($_POST['ComeIn'])) { //NAME OF THE BUTTON CLIKED

if (empty($_POST['email']) || empty($_POST['pwd'])) {   //IF EMPTY
$error = "Username or Password is invalid";
}
else 
    {

        $username=$_POST['email'];
        $password=$_POST['pwd'];
        include ('connection.php');


        $username = mysql_real_escape_string($username);
        $password = mysql_real_escape_string($password);


        $query = mysql_query("SELECT * from user_account where Password='$password' AND Email='$username'", $connection);
        $row1= mysql_fetch_array($query);
        $rows = mysql_num_rows($query);

            if ($rows == 1) {   //IF OK
                if ($row1['AccType'] == "Teacher")
                {
                    $_SESSION['login_user']=$username; // Initializing Session
                    header("location: teachers/teacherprofile.php"); // Redirecting To Other Page
                }
                else if ($row1['AccType'] == "Student")
                {
                    $_SESSION['login_user']=$username; // Initializing Session
                    header("location: students/studentprofile.php"); // Redirecting To Other Page
                }

                else
                {
                    echo ("<script language = 'Javascript'>
                            window.alert('Incorrect Input!')
                            window.location.href='index.php'
                            </script>");
                }
            } else 
                {
                    echo ("<script language = 'Javascript'>
                            window.alert('Incorrect Input!')
                            window.location.href='index.php'
                            </script>");
                }
                }

        mysql_close($connection); 
    }

?>

But this admin login form is not working and it has almost the same code. It's not going anywhere. It's just going to login2.php and none of the PHP functions are working. Below is the login2.php:

<?php
session_start(); // Starting Session
$error=''; 
include ('connection.php');



if (isset($_POST['login'])) { //NAME OF THE BUTTON CLIKED

    if (empty($_POST['aemail']) || empty($_POST['apwd'])) { //IF EMPTY
    $error = "Username or Password is invalid";
    }
    else //TEXTFIELDS NOT EMPTY
        {

            $username=$_POST['aemail'];
            $password=$_POST['apwd'];
            include ('connection.php');


            $username = mysql_real_escape_string($username);
            $password = mysql_real_escape_string($password);


            $query = mysql_query("SELECT * from service_account where CS_Password='$password' AND CS_Email='$username'", $connection);
            $row1= mysql_fetch_array($query);
            $rows = mysql_num_rows($query);



                if ($rows == 1) {   //IF OK
                    if ($row1['SA_Type'] == "Admin")
                    {
                        $_SESSION['login_user']=$username; // Initializing Session
                        header("location: admin/admin_dashboard.php"); // Redirecting To Other Page
                    }
                    else if ($row1['SA_Type'] == "Customer Service")
                    {
                        $_SESSION['login_user']=$username; // Initializing Session
                        header("location: cservice/cs_inquiry.php"); // Redirecting To Other Page
                    }
                    else
                    {
                        $error = "Username or Password is invalid";
                        header("location: login_csa.php");
                    }
                } else 
                    {
                    $error = "Username or Password is invalid";
                    header("location: login_csa.php");
                    }

            mysql_close($connection); 
        }
}

?>

Im debugging this for two days now. THe weird part is, When I tried to use the system in localhost, it's perfectly working. When I put it in iPage.com, that happens. Any suggestions?

Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131
  • you can get rid the `$connection` in your `mysql_query()`. and is there any error? – Sam Teng Wong Jan 28 '16 at 02:43
  • Your script is probably dying or not meeting any of the conditions. Put this `ini_set('display_errors', 1); error_reporting(-1);` at the top of your script and show us what errors pop up. – Darren Jan 28 '16 at 02:44
  • 1
    the other thing is that `mysql_*` is deprecated.... check the php version that you are running right now... – Sam Teng Wong Jan 28 '16 at 02:47
  • when i put the ini_set('display_errors', 1); error_reporting(-1); I got this error: Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /hermes/bosoraweb126/b1216/ipg.meteacherscom/login2.php:2) in /hermes/bosoraweb126/b1216/ipg.meteacherscom/login2.php on line 4 – rod ortega Jan 28 '16 at 02:49
  • Side note, you should not be storing passwords in plaintext. – Rasclatt Jan 28 '16 at 02:52
  • You probably have an invisible unicode character at the beginning of your script. – Darren Jan 28 '16 at 02:53
  • The first user login form is working, but the other one, even having almost the same code, is not working. – rod ortega Jan 28 '16 at 02:55
  • @Darren how would I kow if there is any? – rod ortega Jan 28 '16 at 02:55
  • @rodortega Check out [this](http://stackoverflow.com/a/3085715/2518525) answer, and give it a shot! – Darren Jan 28 '16 at 02:56
  • 1
    @Darren It worked! There are invisible characters inside. I love you now (no homo). – rod ortega Jan 28 '16 at 03:07
  • @rodortega perfect, don't worry we've all been there man! I spent a week once trying to fix the same issue and it was because there were 2 spaces after my closing `?>`. Now that's messed up! Do you want me to put it as an answer so you can close your question? – Darren Jan 28 '16 at 03:08
  • Remove everything before the –  Jan 28 '16 at 03:08
  • @Darren unicode or ASCII ? –  Jan 28 '16 at 03:09
  • @Devashish just 2 spaces after, that's why you should never close your script off with `?>`, just leave it gone! (*it's counted as output, causing issues haha*) – Darren Jan 28 '16 at 03:10
  • @Darren hey darren, rod is not replying, but I request you to post the answer :) –  Jan 28 '16 at 03:17
  • @Devashish There you go, a reasonable explanation answer :) – Darren Jan 28 '16 at 03:23

1 Answers1

1

This is a common occurrence and is called "The White Screen of Death". You should turn on error reporting at the top of your script to figure out what the issue is, that's causing this!

<?php
ini_set('display_errors', 1);
error_reporting(-`);

Note: This is almost always because output was sent to the browser before you tried to start a session or do something.

The above will tell you exactly what the issue was, and in your case it did. Stating:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /hermes/bosoraweb126/b1216/ipg.meteacherscom/login2.php:2) in /hermes/bosoraweb126/b1216/ipg.meteacherscom/login2.php on line 4

Now if you didn't have anything echo'ing to the screen before you started the session, then your issue would have to be some invisible characters within your PHP script.

If that's your case (which it seems, was), then you should follow this answer below to remove those invisible characters (bad encoding). Your script will run again properly.

Community
  • 1
  • 1
Darren
  • 12,786
  • 3
  • 34
  • 71
  • 1
    And I know where that name came from (the white screen of death) :) –  Jan 28 '16 at 03:25