• PHP Help General Help
  • [RESOLVED] How to resolve Undefined index:phplogin and Undefined variable :username error

Hi,
I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that,

After doing some changes when i run it on my local server it was working fine but giving some errors those are

Notice: Undefined index: phplogin in C:\Inetpub\wwwroot\sampleft\index.php on line 116

Notice: Undefined variable: username in C:\Inetpub\wwwroot\sampleft\index.php on line 116

and the code is

<?php
 session_start(); 

 require_once( 'includes/settings.php' );
 if(isset($_POST['submit']))
 {
    $username=$_POST['email'];
    $password = $_POST['password'];

$login_query = "select user_email, user_group,user_password from person where user_email = '$username' and user_password = '$password' ";

$res = dbconnect($login_query);




 //)

 $num_rows = mysql_num_rows($res);
 if ($num_rows)
 {
    while ($myrow = mysql_fetch_row($res))
    {
       $user_group = $myrow[1];

    }


   $_SESSION['user'] = $username;
   $_SESSION['password']=$password;
   $_SESSION['phplogin'] = true;
   $_SESSION['user_group'] = $user_group;

   header('Location: main.php'); 
   exit;
}

}

?>
<!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"><!-- InstanceBegin template="/Templates/maintemp.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Login Page</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.style9 {color: #CC0000}
.style2 {color: #FF0000}
-->
</style>
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
.style7 {
    font-size: 24px;
    color: #FFFFFF;
    font-weight: bold;
}
.style9 {font-size: 19px; color: #FFFFFF; font-weight: bold; }
-->
</style>
</head>

<body>
<table width="746" height="377" border="0" cellspacing="0" bordercolor="#B5C3DE">
  <tr>
    <td height="64" colspan="4" bordercolor="#FFFFFF" bgcolor="#000066">
    <p class="style9">Sample Feasibility Tool </p></td>
  </tr>
  <tr>
    <td width="400" height="21" bgcolor="#CCCCCC">
    <?php
     if (isset($_SESSION['phplogin']))
     {
        $user = $_SESSION['user'];
        echo "<span class=\"style10\">Welcome $user </span>";
     }
     ?></td>


<td width="88" height="21" bgcolor="#CCCCCC">
<?php
 if (isset($_SESSION['phplogin']))
 {

    echo "<p><a href=\"logout.php\" class=\"style9\">log out</a></p>";
 }
 ?></td>
  </tr>
  <tr>
    <td height="224" colspan="4"><!-- InstanceBeginEditable name="EditRegion3" -->


  <p align="center"><strong>Please login to use the tool</strong></p>
  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  <table align="center" border="1" cellspacing="0" cellpadding="3">
  <tr><td>Enter Full PSL Email:</td><td>
  <input type="text" name="email" maxlength="50">
  </td></tr>
  <tr><td>Password:</td><td>
  <input type="password" name="password" maxlength="50">
  </td></tr>
  <tr><td colspan="2" align="right">
  <input type="submit" name="submit" value="Login">
  </td></tr>
  </table>
  </form>

  <?php

  if($_SESSION['phplogin'] != true && $username!="")
  {
     echo "<span class=\"style9\">You have entered a non-registered email</span>";

     echo "<br><strong><span class=\"style2\"><em>(NOTE: In case you are a new user, please email Michael O'Donnell for a login)</em></span></strong>";
 }

  ?>

  <p>&nbsp;</p>
<!-- InstanceEndEditable -->
<p>&nbsp;</p></td>
  </tr>
  <tr>
    <td width="188" height="21" bgcolor="#CCCCCC">

<?php
 if (isset($_SESSION['phplogin']))
 {
    echo "<span class=\"style10\"><a href=\"main.php\">Main Page</a> </span>";
 }

?></td>
  </tr>
  <tr>
    <td width="188" height="21" bgcolor="#CCCCCC">
    <?php
     if (isset($_SESSION['phplogin']) && $_SESSION['user_group'] == 'A')
     {

    echo "<span class=\"style10\"><a href=\"administration.php\">administration</a></span>";
 }

?>
</td>
  </tr> 
</table>
</body>
<!-- InstanceEnd --></html>

i thought these eroors will go when i put this to main server but i got some more errors and those are

Code: ( text )
Warning: session_start() [function.session-start]: open(C:\sessiondata\sess_7622cc37a4f8bcb6af1cc6981 3daa148, O_RDWR) failed: Permission denied (13) in C:\Inetpub\wwwroot\ft\index.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\ft\index.php:2) in C:\Inetpub\wwwroot\ft\index.php on line 2

Warning: Unknown: open(C:\sessiondata\sess_7622cc37a4f8bcb6af1cc6981 3daa148, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\sessiondata) in Unknown on line 0

Please help me to destry them,
Looking forward for any reply .......Thanks

    When posting PHP code, please use the board's [PHP][/PHP] bbcode tags - they much your code much easier to read and analyze. Since you had a large amount of code, I've already added these tags, but please keep this in mind for the future.

    Also, you should never place user-supplied data directly into a SQL query. Instead, you should always sanitize it first with a function such as [man]mysql_real_escape_string/man.

    To address your error messages...

    siyaverma wrote:

    Notice: Undefined index: phplogin in C:\Inetpub\wwwroot\sampleft\index.php on line 116

    Notice: Undefined variable: username in C:\Inetpub\wwwroot\sampleft\index.php on line 116

    Obviously, $_SESSION['phplogin'] and $username don't exist. Since you didn't use isset() or something of that nature, PHP issued notices letting you know that you attempted to use variables that didn't exist.

    siyaverma wrote:

    i thought these eroors will go when i put this to main server but i got some more errors and those are

    Well, first of all, the messages themselves technically should have gone away, because you should never be displaying PHP error messages period on a production server. Since you do have them, I'll assume you retrieved them from a log that isn't accessible by the rest of the world.

    As for the errors about sessions, you need to talk to your sysadmin as PHP spells out the problem quite clearly: it doesn't have permission to save data in c:\sessiondata. If you are the sysadmin of this server, then you need to allow the IUSR_(ComputerName) account read/write privileges in the ACL for that folder.

      Thanks Thanks very much somehow i was kept missing session.save_path in php.ini ,i ts working now ,but everything is working good all errors are resolved

      Thank you and i will take care of quotes from now and just one more question ,one error is coming

      Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Inetpub\wwwroot\ft\main.php:1) in C:\Inetpub\wwwroot\ft\main.php on line 2

      how to resolve this ,is it also something which is not set or already set or something

      Thanks

        This error means that you outputted data on the first line of main.php (perhaps a space or something before the PHP tag?).

          Thanks
          Thanks a lot ,it worked ,Appreiciated.

            Thanks to remind me i was almost missing that part.

              Write a Reply...