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 14 of 14
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Undefined index: op in C:\Users\Xampp\htdocs\APP\login\login2.php o

    PHP Code:
    <?php
        session_start
    ();
        
    // dBase file
        
    include "config.php";

        if (
    $_GET["op"] == "login")
      {
      if (!
    $_GET["username"] || !$_GET["password"])
          {
          die(
    "You need to provide a username and password.");
          }
      
      
    // Create query
      
    $q "SELECT * FROM `users` "
          
    ."WHERE `username`='".$_GET["username"]."' "
          
    ."AND `password`=PASSWORD('".$_GET["password"]."') "
          
    ."LIMIT 1";
      
    // Run query
      
    $r mysql_query($q);

      if ( 
    $obj = @mysql_fetch_object($r) )
          {
          
    // Login good, create session variables
          
    $_SESSION["id"] = $obj->id;
          
    $_SESSION["user"] = $_GET["username"];
          
    $_SESSION["time"] = time();

          
    // Redirect to member page
          
    Header("Location: welcome.php");
          }
      else
          {
          
    // Login not successful
          
    die("Sorry, could not log you in. Wrong login information.");
          }
      }
        else
      {
    //If all went right the Web form appears and users can log in
      
    echo "<form action=\"?op=login\" method=\"GET\">";
      echo 
    "Username: <input name=\"username\" name=\"username\" size=\"32\"><br />";
      echo 
    "Password: <input type=\"password\" name=\"password\" size=\"32\"><br />";
      echo 
    "<input type=\"submit\" value=\"Login\">";
      echo 
    "</form>";
      }
        
    ?>
    Last edited by amcf1992; 01-27-2014 at 03:43 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can fix it by using an isset($_GET['op']) before attempting to read it in that if statement.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You can fix it by using an isset($_GET['op']) before attempting to read it in that if statement.
    This is my code with your suggestion, however, its still not working

    PHP Code:
    <?php
        session_start
    ();
        
    // dBase file
        
    include "config.php";
    isset(
    $_GET['op']){
        if (
    $_GET["op"] == "login"){
      {
      if (!
    $_GET["username"] || !$_GET["password"])
          {
          die(
    "You need to provide a username and password.");
          }
      }
      }
      }
        
      
    // Create query
      
    $q "SELECT * FROM `users` "
          
    ."WHERE `username`='".$_GET["username"]."' "
          
    ."AND `password`=PASSWORD('".$_GET["password"]."') "
          
    ."LIMIT 1";
      
    // Run query
      
    $r mysql_query($q);

      if ( 
    $obj = @mysql_fetch_object($r) )
          {
          
    // Login good, create session variables
          
    $_SESSION["id"] = $obj->id;
          
    $_SESSION["user"] = $_GET["username"];
          
    $_SESSION["time"] = time();

          
    // Redirect to member page
          
    Header("Location: welcome.php");
          }
      else
          {
          
    // Login not successful
          
    die("Sorry, could not log you in. Wrong login information.");
          }
      }
        else
      {
    //If all went right the Web form appears and users can log in
      
    echo "<form action=\"?op=login\" method=\"GET\">";
      echo 
    "Username: <input name=\"username\" name=\"username\" size=\"32\"><br />";
      echo 
    "Password: <input type=\"password\" name=\"password\" size=\"32\"><br />";
      echo 
    "<input type=\"submit\" value=\"Login\">";
      echo 
    "</form>";
      }

        
    ?>
    I doing something wrong with the curly brackets I suspect.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Instead of
    PHP Code:
     if ($_GET["op"] == "login"
    use
    PHP Code:
     if (isset($_GET["op"] ) && $_GET["op"] == "login"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Instead of
    PHP Code:
     if ($_GET["op"] == "login"
    use
    PHP Code:
     if (isset($_GET["op"] ) && $_GET["op"] == "login"
    login isn't selecting user row
    PHP Code:
    <?php
        session_start
    ();
        
    // dBase file
        
    include "config.php";

        if (isset(
    $_GET["op"] ) && $_GET["op"] == "login")  
      {
      if (!
    $_GET["username"] || !$_GET["password"])
          {
          die(
    "You need to provide a username and password.");
          }
      
      
    // Create query
      
    $q "SELECT * FROM `users` "
          
    ."WHERE `username`='".$_GET["username"]."' "
          
    ."AND `password`=PASSWORD('".$_GET["password"]."') "
          
    ."LIMIT 1";
      
    // Run query
      
    $r mysql_query($q);

      if ( 
    $obj = @mysql_fetch_object($r) )
          {
          
    // Login good, create session variables
          
    $_SESSION["id"] = $obj->id;
          
    $_SESSION["user"] = $row['username'];
          
    $_SESSION["time"] = time();

          
    // Redirect to member page
          
    Header("Location: welcome.php");
          }
      else
          {
          
    // Login not successful
          
    die("Sorry, could not log you in. Wrong login information.");
          }
      }
        else
      {
    //If all went right the Web form appears and users can log in
      
    echo "<form action=\"?op=login\" method=\"GET\">";
      echo 
    "Username: <input name=\"username\" name=\"username\" size=\"32\"><br />";
      echo 
    "Password: <input type=\"password\" name=\"password\" size=\"32\"><br />";
      echo 
    "<input type=\"submit\" value=\"Login\">";
      echo 
    "</form>";
      }
        
    ?>

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Count the number of records returned in a num_rows call, and if it's not 1 than there's no match on the where condition.
    There is no $row to work with either, so obviously the $_SESSION['user'] will be set to null.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Count the number of records returned in a num_rows call, and if it's not 1 than there's no match on the where condition.
    There is no $row to work with either, so obviously the $_SESSION['user'] will be set to null.
    PHP Code:
    <?php
        session_start
    ();
        
    // dBase file
        
    include "config.php";
    ini_set('display_errors'1);
        if (isset(
    $_GET["op"] ) && $_GET["op"] == "login")  
      {
      if (!
    $_GET["username"] || !$_GET["password"])
          {
          die(
    "You need to provide a username and password.");
          }
      
      
    // Create query
      
    $q "SELECT * FROM `users` "
          
    ."WHERE `username`='".$_GET["username"]."' "
          
    ."AND `password`=PASSWORD('".$_GET["password"]."') "
          
    ."LIMIT 1";
      
    // Run query
      
    $r mysql_query($q);
      
    $row mysql_assoc_array($r);
      
    $count mysql_num_rows($r);
      if (
    $obj mysql_fetch_object($r) && $count == 1)
          {
          
    // Login good, create session variables
        
    $_SESSION["id"] = $row['id'] =$obj->id;
          
    $_SESSION["user"] = $row['username'] = $obj->username;
        
    $_SESSION["time"] = time();
          
    // Redirect to member page
          
    Header("Location: welcome.php");
          }

      else
          {
          
    // Login not successful
          
    die("Sorry, could not log you in. Wrong login information.");
        
    header("Location: login2.php");
          }
    }
         {
    //If all went right the Web form appears and users can log in
      
    echo "<form action=\"?op=login\" method=\"GET\">";
      echo 
    "Username: <input name=\"username\" name=\"username\" size=\"32\"><br />";
      echo 
    "Password: <input type=\"password\" name=\"password\" size=\"32\"><br />";
      echo 
    "<input type=\"submit\" value=\"Login\">";
      echo 
    "</form>";
      }
        
    ?>
    added $count and $row, still not returning successfully.

  • #8
    Regular Coder
    Join Date
    Sep 2002
    Posts
    459
    Thanks
    0
    Thanked 20 Times in 20 Posts
    PHP Code:
    <?php
    ini_set
    ('display_errors'1);

    //--- start session / continue session ---//
    session_start();

    //--- db Connect ---//
    include "config.php";


    $check_login = (isset($_GET['op']) && $_GET['op']=='login')? 1:0;


    if(
    $check_login){
    $user $_GET['username'];
    $pass $_GET['password'];
      
    // Create query
      
    $q  "SELECT * FROM `users` ";
      
    $q .= "WHERE username = $user ";
      
    $q .= "AND password= $password ";
      
    $q .= "LIMIT 1";
      
    $r mysql_query($q);
      
    $count mysql_num_rows($r);

    if(
    $count == 1){
      
    $row mysql_assoc_array($r);
     
    $obj mysql_fetch_object($r)
    //--- start login process ---//
    }
    else{
    //--- return to login page ---//
        
    header("Location: login2.php");
    }


    }
    //[end login check]

    //add else staement her if needed
    ?>
    try that
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You cannot fetch twice without resetting the resultset pointer. Choose either to fetch using an array or an object, not both.
    Also, you do not need to put the count in the if. Since its not a loop it will only execute once, and the results of the assignment are the verification. The count is to use another branch to determine if you can even process a record in order to provide an else clause for a failure message.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #10
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    $_SESSION["valid_id"] = $obj->id $sessionid;
    $_SESSION["valid_user"] = $_POST["username"] = $sessUser;
    $_SESSION["valid_time"] = time() = $time;
    echo 
    $Sessionid;
    echo 
    $sessUser;
    echo 
    $time
    Having an issue echoing session vars

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You haven't defined these variables, nor are they session variables. Session variables are always within the session superglobal, and can only be extracted as needed or referenced.
    $sessionid, $sessUser, and $time all do not exist. Since you've now chained, every variable in the same line is null.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #12
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You haven't defined these variables, nor are they session variables. Session variables are always within the session superglobal, and can only be extracted as needed or referenced.
    $sessionid, $sessUser, and $time all do not exist. Since you've now chained, every variable in the same line is null.
    I got rid of the call to nonexistant variables.

    This is what I am trying to accomplish

    login2.php?op=login&username=admin&password=admin
    but I get this url

    login2.php?username=admin&password=admin

    My code now:

    PHP Code:
    <?php 
    ini_set
    ('display_errors'1); 

    //--- start session / continue session ---// 
    session_start(); 

    //--- db Connect ---// 
    include "config.php"

    $check_login = (isset($_GET['login']) && $_GET['op']=='login')? 1:0


    if(
    $check_login){ 
    $user $_GET['username']; 
    $pass $_GET['password'];
    $op $_GET['op']; 
      
    // Create query 
      
    $q  "SELECT * FROM `users` "
      
    $q .= "WHERE username = '$user' "
      
    $q .= "AND password= '$password' "
      
    $q .= "LIMIT 1"
      
    $r mysql_query($q);
    $obj mysql_fetch_object($r);
    $_SESSION["valid_id"]= $obj->id;
    $_SESSION["valid_user"] = $obj->username;
    $_SESSION["valid_time"] = time();

          
    // Redirect to member page 
          
    Header("Location: welcome.php"); 
          } 
    else {
      


      echo 
    "<form action=\"?op=login\" method=\"GET\">";
      echo 
    "Username: <input name=\"username\" name=\"username\" size=\"32\"><br />";
      echo 
    "Password: <input type=\"password\" name=\"password\" size=\"32\"><br />";
      echo 
    "<input type=\"submit\" value=\"Login\">";
      echo 
    "</form>";
      }
      
      
        
    ?>

  • #13
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,077
    Thanks
    2
    Thanked 320 Times in 312 Posts
    When you use a GET method form, the form fields at the only thing that are submitted on the end of the url. You would need to use a hidden form field for the op value.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That's how HTML works.
    If you want to include it in the GET than you have to add an input for it. The action querystring is overwritten by the submitted get data.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    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
    •