AmbientGuitar Posted December 4, 2020 Share Posted December 4, 2020 <!DOCTYPE html> <?php // Check if the user is already logged in, if yes then redirect him/her to dashboard page if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ print('<div class="page-header">'); print('<h1>Hi, <b>'); echo htmlspecialchars($_SESSION["username"]); print('</b> Welcome to our site.</h1></div>'); exit; } // Define variables and initialize with empty values $username = $password = $confirm_password = ""; $username_err = $password_err = $confirm_password_err = ""; ?> <html lang="en"> <head> <title>Opus Reports Login</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css"> <style type="text/css"> body{ font: 12px verdana; text-align: center; } </style> <!--===============================================================================================--> <link rel="icon" type="image/png" href="images/icons/favicon.ico"/> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="fonts/Linearicons-Free-v1.0.0/icon-font.min.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="vendor/animate/animate.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="vendor/animsition/css/animsition.min.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="vendor/daterangepicker/daterangepicker.css"> <!--===============================================================================================--> <link rel="stylesheet" type="text/css" href="css/util.css"> <link rel="stylesheet" type="text/css" href="css/main.css"> <!--===============================================================================================--> </head> <?Php $mycolour = ''; if (!empty( $_COOKIE['favcolour'])) { $mycolour = $_COOKIE['favcolour']; } ?> <body style="background-color: <?Php echo $mycolour;?>;"> <div class="limiter"> <div class="container-login100"> <div class="wrap-login100"> <form class="login100-form validate-form"> <span class="login100-form-title p-b-43" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> Login to Reports </span> <div class="wrap-input100 validate-input" data-validate = "A Current Valid UserID is required for access:e.g. 1234"> <input class="input100" type="text" name="userid" id="userid" value="Admin" autocomplete="on"> <span class="focus-input100"></span> <span class="label-input100">UserId</span> </div> <div class="wrap-input100 validate-input" data-validate="A Password is required"> <input class="input100" type="password" name="password" id="password" maxlength="8" autocomplete="on"> <span class="focus-input100"></span> <span class="label-input100">Password</span> </div> <div class="flex-sb-m w-full p-t-3 p-b-32"> <div class="contact100-form-checkbox"> <input class="input-checkbox100" id="ckb1" type="checkbox" name="remember-me"> <label class="label-checkbox100" for="ckb1"> Remember me </label> </div> <div> <a href="#" class="txt1"> Forgot Password? </a> </div> </div> <div class="container-login100-form-btn"> <button type="submit" class="login100-form-btn"> Login </button> </div> <div class="text-center p-t-46 p-b-20"> <span class="txt2"> or sign up using </span> </div> <div class="login100-form-social flex-c-m"> <a href="#" class="login100-form-social-item flex-c-m bg1 m-r-5"> <i class="fa fa-facebook-f" aria-hidden="true"></i> </a> <a href="#" class="login100-form-social-item flex-c-m bg2 m-r-5"> <i class="fa fa-twitter" aria-hidden="true"></i> </a> </div> </form> <div class="login100-more" style="background-image: url('images/bg-01.png');"> </div> </div> </div> </div> <?Php $dsn = 'odbc:MY_DSN'; $user = '8888'; $pass = '****'; //$pdo = new PDO($dsn, $user, $pass); //sasql_connect("uid=dba;pwd=sql"); try { $pdo = new PDO($dsn, $user, $pass); $pdo_status = "Sybase Connected Okay" . "\n"; //echo $pdo_status; } catch(PDOException $e) { error_log($e->getMessage()); echo 'Connection failed! No connection no queries!: ' . $e->getMessage(); } /* Enable error reporting for all types except for deprecated and strict. */ error_reporting(E_ALL); //if($_SERVER["REQUEST_METHOD"] == "POST"){ // Check if username is empty if(empty(trim($_POST["userid"]))){ $username_err = "Please enter a correct userid."; } else{ $username = trim($_POST["userid"]); } // Check if password is empty if(empty(trim($_POST["password"]))){ $password_err = "Please enter your password."; } else{ $password = trim($_POST["password"]); } /* print('<span class="help-block">'); echo $password_err; print('</span>'); */ // Validate credentials if(empty($username_err) && empty($password_err)){ // No Errors do select // Prepare a select statement Console.log($username); print_r ($username); $sql = 'Select userid,username,userpassword from users where userid = :username'; if($stmt = $pdo->prepare($sql)){ // Bind variables to the prepared statement as parameters //$stmt->bindParam('s', $param_username, PDO::PARAM_STR); // Set parameters $param_username = trim($_POST["userid"]); // Attempt to execute the prepared statement //$stmt->execute(['transactionNo' => $number, 'tillid' => $till]); if($stmt->execute(['userid' => $username])){ // Check if username exists, if yes then verify password //echo ($userid); $result=$stmt->fetch(pdo::FETCH_ASSOC); If(!$result){ echo "failed Login"; } if($stmt-> rowCount() == 1){ if($row = $stmt->fetch()){ $id = $row["userid"]; $username = $row["username"]; $hashed_password = $row["password"]; if(password_verify($password, $hashed_password)){ // Password is correct, so start a new session session_start(); // Store data in session variables $_SESSION["loggedin"] = true; $_SESSION["id"] = $id; $_SESSION["username"] = $username; $_SESSION['loggedin_time'] = time(); // Redirect user to welcome page perhaps header('location: dashboard.php'); } else{ // Display an error message if password is not valid $password_err = "The password you entered was not valid."; } } } else{ // Display an error message if username doesn't exist $username_err = "No account found with that username."; } } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement unset($stmt); } } // Close connection unset($pdo); file_put_contents( 'C:\temp\logs\debug' . time() . '.log', var_export( $username, true), FILE_APPEND); //} ?> <!--===============================================================================================--> <script src="vendor/jquery/jquery-3.2.1.min.js"></script> <!--===============================================================================================--> <script src="vendor/animsition/js/animsition.min.js"></script> <!--===============================================================================================--> <script src="vendor/bootstrap/js/popper.js"></script> <script src="vendor/bootstrap/js/bootstrap.min.js"></script> <!--===============================================================================================--> <script src="vendor/select2/select2.min.js"></script> <!--===============================================================================================--> <script src="vendor/daterangepicker/moment.min.js"></script> <script src="vendor/daterangepicker/daterangepicker.js"></script> <!--===============================================================================================--> <script src="vendor/countdowntime/countdowntime.js"></script> <!--===============================================================================================--> <script src="js/main.js"></script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/ Share on other sites More sharing options...
requinix Posted December 4, 2020 Share Posted December 4, 2020 Not getting errors is a good thing. How about you try describing your problem? What is supposed to happen and what is actually happening? Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582822 Share on other sites More sharing options...
dodgeitorelse3 Posted December 4, 2020 Share Posted December 4, 2020 How does the section near top to define variables work? Wouldn't that make $username be the value of $confirm_password? Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582823 Share on other sites More sharing options...
requinix Posted December 4, 2020 Share Posted December 4, 2020 No, for a couple reasons: 1. Regular assignment (=) assigns values. $username gets the value of $confirm_password - it's not literally saying "$username is the same thing as $confirm_password". 2. Technically, $a = $b = $c does not say $b=$c; $a=$b but actually $b=$c; $a=$c. It's a minor point that basically never matters. So the statement is really more like $confirm_password = ""; $username = "". Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582825 Share on other sites More sharing options...
AmbientGuitar Posted December 4, 2020 Author Share Posted December 4, 2020 (edited) Sorry. Notice: Undefined index: userid in C:\inetpub\wwwroot\Reports\login.php on line 162 Notice: Undefined index: password in C:\inetpub\wwwroot\Reports\login.php on line 171 When I add userid and password it checks users table if valid then should redirect to dashboard.php Edited December 4, 2020 by AmbientGuitar Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582826 Share on other sites More sharing options...
requinix Posted December 4, 2020 Share Posted December 4, 2020 $_POST["userid"] and $_POST["password"] will only exist after the form has been submitted. The first time you load the page, obviously it won't have been, but that code there is still trying to run. That thing you commented out? //if($_SERVER["REQUEST_METHOD"] == "POST"){ That detects whether the form was submitted. You need it. Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582827 Share on other sites More sharing options...
AmbientGuitar Posted December 4, 2020 Author Share Posted December 4, 2020 (edited) Sorry, I have uncommented and it has removed the errors. The console is showing nothing but redirection isn't working. How do you debug php. I am only doing this s few weeks! Edited December 4, 2020 by AmbientGuitar Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582829 Share on other sites More sharing options...
requinix Posted December 4, 2020 Share Posted December 4, 2020 There are two other problems, but they should be giving you error messages. Do you see any error messages? Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582830 Share on other sites More sharing options...
jodunno Posted December 4, 2020 Share Posted December 4, 2020 5 minutes ago, AmbientGuitar said: but redirection isn't working. terminate the script after a header redirect: // Redirect user to welcome page perhaps header('location: dashboard.php'); exit; Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582831 Share on other sites More sharing options...
AmbientGuitar Posted December 4, 2020 Author Share Posted December 4, 2020 Tried this no joy! Apologies as I say I am quite new to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582832 Share on other sites More sharing options...
jodunno Posted December 4, 2020 Share Posted December 4, 2020 look closer at your code, please: <span class="login100-form-title p-b-43" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> it seems as though you may be new to html as well. action and method attributes belong with the form element not the span element. also, just use action="#" or leave it blank action="" versus the awful idea of PHP_SELF. you should recode your form correctly. you should also read about get and post methods. your php script should be separated into post and get content: if server request method = post then check login etc redirect to dashboard else show your form page do you not understand the problems with your code? try reading about forms and handling form submissions (posts). remember to exit after a header redirect. Best wishes. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582834 Share on other sites More sharing options...
requinix Posted December 4, 2020 Share Posted December 4, 2020 Also note that PHP errors do not show up in your browser's developer console*. They will be outputted as messages right into the page, or they'll show up in a log file, or they'll not show up at all, depending on how your PHP is set up. It's confusing to me to need to say this because you clearly saw the Undefined Index notices earlier. Are you using some PHP extension to get errors into the console? Does it support doing that with fatal errors too? (* edit: unless you have one of those PHP+browser extensions that lets you do that, but those are rarely used anymore) Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582837 Share on other sites More sharing options...
AmbientGuitar Posted December 5, 2020 Author Share Posted December 5, 2020 Thanks guys! Making progress. I think its a PDO param that's causing this. However, jodunno was correct. My HTML i snot as it used to be. Thanks. I will get back when i have a solution. I have made progress. Quote Link to comment https://forums.phpfreaks.com/topic/311801-please-help-i-am-new-to-php-and-im-not-getting-any-errors-in-console-what-am-i-doing-wrong/#findComment-1582840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.