
rwahdan1978
Members-
Posts
11 -
Joined
-
Last visited
Everything posted by rwahdan1978
-
Hi I have a feild in DB that have time() like 2025-04-26 20:30:00. I want to check and get difference between curremt time and the time in DB. example: time in DB is 2025-04-26 20:30:00 current time is 2025-04-26 20:40:00 the time allowed is 15 minutes so from the above example its only passing 10 minutes and have 5 minutes left, how to calculate that?
-
Him I have an OTP sysem where the user will enter the OTP that was sent to their email, in the DB it is saving the OTP and the expiry after 15 minutes. After they use it, I need to delete both from DB. I am able to set the number back to 0 since it is an integer. How to reset the dattime field to show 0000-00-00 00:00:00? $sqlUpdate = "UPDATE login_users SET otp_reset = 0, otp_expiry = ??? WHERE username_email = '$myusername'"; if(mysqli_query($db,$sqlUpdate)) { ..... }
-
I am trying to include a php header file to my page but it is not working. <?php session_start(); include("header.php"); $the_email = $_GET['email']; $_SESSION['user_email'] = $the_email; ?> and header have a navbar header.php <?php session_start(); $authenticated = false; $isadmin = false; if ($_SESSION['user']) { $thename = $_SESSION['user_name']; $theimage = $_SESSION['user_photo']; $authenticated = true; $isadmin = false; } if ($_SESSION['admin']) { $thename = $_SESSION['admin_name']; $authenticated = true; $isadmin = true; } ?> <!doctype html> <html lang="en"> <head> <!-- Required Meta Tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Document Title, Description, and Author --> <title>Teacher License System</title> <meta name="description" content="Wave is a Bootstrap 5 One Page Template."> <meta name="author" content="BootstrapBrain"> <!-- Favicon and Touch Icons --> <link rel="icon" type="image/png" sizes="512x512" href="./assets/favicon/favicon-512x512.png"> <!-- Google Fonts Files --> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600;700&family=Satisfy&display=swap" rel="stylesheet"> <!-- CSS Files --> <link rel="stylesheet" href="./assets/css/wave-bsb.css"> <!-- BSB Head --> </head> <body data-bs-spy="scroll" data-bs-target="#bsb-tpl-navbar" data-bs-smooth-scroll="true" tabindex="0"> <!-- Header --> <header id="header" class="sticky-top bsb-tpl-header-sticky bsb-tpl-header-sticky-animationX"> <!-- Navbar 1 - Bootstrap Brain Component --> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="index.php"> <img src="/assets/img/logo.png" width="40" height="40" class="d-inline-block align-top" alt=""> TLS CS C2&3 </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon">test</span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link text-dark" href="index.php">Home</a> </li> <li class="nav-item"> <a class="nav-link text-dark" href="about.php">About</a> </li> <li class="nav-item"> <a class="nav-link text-dark" href="services.php">Services</a> </li> <li class="nav-item"> <a class="nav-link text-dark" href="pricing.php">Pricing</a> </li> <li class="nav-item"> <a class="nav-link text-dark" href="contact.php">Contact US</a> </li> </ul> <?php if ($isadmin) { ?> <ul class="navbar-nav"> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle text-dark" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Hello, <?= $thename ?> </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="main.php">TLS Materials</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="logout.php">Logout</a></li> </ul> </li> </ul> <?php } else if ($authenticated) { ?> <img src='/files/<?=$theimage ?>' width="75px"> <ul class="navbar-nav"> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle text-dark" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"><?= $thename ?> </a> <ul class="dropdown-menu" aria-labelledby="navbarDropdown"> <li><a class="dropdown-item" href="profile.php">My Profile</a></li> <li><a class="dropdown-item" href="main.php">TLS Materials</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="logout.php">Logout</a></li> </ul> </li> </ul> <?php } else {?> <ul class="navbar-nav"> <li class="navbar-item"> <a href="register.php" class="btn btn-outline-primary me-2">Register</a> </li> <li class="navbar-item"> <a href="login.php" class="btn btn-primary">Login</a> </li> </ul> <?php } ?> </div> </div> </nav> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> </header> why is that? Am i missing something?
-
Hi I am trying to send email through php as html template. Below code, if I put the headers it will get the custom error message that the email is not sent. If I remove the headers it will send the email but the email will be not formatted as html and it will send the whole template.php as a text. $to = $myusername; $subject = "OTP - RESET PASSWORD"; $headers = array( 'MIME-Version' => '1.0', 'Content-type' => 'text/html;charset=UTF-8', 'From' => '[email protected]', 'Reply-To' => '[email protected]' ); //$message = "hi!"; ob_start(); include("mail-template.php"); $message = ob_get_contents(); ob_end_clean(); $sent = mail($to, $subject, $message); if(!$sent){ echo "Error: Message not sent. Please try again"; }else{ echo "Message was sent successfully"; }
-
I am trying to get the current time and add 10 minutes before saving to DB. $addingTenMinutes= strtotime('now() + 10 minute'); $end_time = date('Y-m-d H:i:s', $addingFiveMinutes); why it is not working?
-
Invalid password when using password_verify
rwahdan1978 replied to rwahdan1978's topic in PHP Coding Help
I made the code more readable and was being able to get some results but a disappointing one! when using the verify it is giving me that the password is not correct, I know it is correct, why? main.php code: <?php session_start(); //include("header.php"); include("config.php"); if ($_SESSION['admin']) { include("header.php"); include("admin_page.php"); } if ($_SESSION['user']) { include("header.php"); include("welcome.php"); } $myusername = ''; $mypassword = ''; $test1 = 0; $test2 = 1; $error=''; if($_SERVER["REQUEST_METHOD"] == "POST") { $myusername = mysqli_real_escape_string($db,$_POST['email']); $mypassword = mysqli_real_escape_string($db,$_POST['password']); $sql = "SELECT * FROM login_users WHERE username_email = '$myusername'"; $result = mysqli_query($db, $sql); $count = mysqli_num_rows($result); if($count == 1) { while($data = mysqli_fetch_array($result)) { if (password_verify($_POST['password'], $data['password'])) { if ($data['IsAdmin'] == $test2) { $_SESSION['admin'] = $_POST['email']; include("header.php"); include("admin_page.php"); header('Location: https://www.ramiwahdan.org/main.php'); } else { $_SESSION['user'] = $_POST['email']; include("header.php"); include("welcome.php"); } } else { echo "error!"; } } -
Hi In my registration page I am taking the password as hashed as below: register.php: <?php session_start(); include("header.php"); $user_email = ""; $email_error = ""; $user_password_error = ""; $confirm_password_error = ""; $admin_password_error = ""; $isadmin = 0; if($_SERVER["REQUEST_METHOD"] == "POST") { $user_email = $_POST["email"]; $user_password = $_POST["password"]; $confirm_password = $_POST["confirmpassword"]; $admin_password = $_POST["adminpassword"]; $isadmin = $_POST["isadmin"]; $error = false; $hashedPass = password_hash($user_password, PASSWORD_DEFAULT); include('connect.php'); $sqlSelect = "SELECT username_email FROM login_users where username_email = '$user_email'"; $result = mysqli_query($conn,$sqlSelect); $count = mysqli_num_rows($result); if ($count == 1) { $email_error = "user email is already in use!"; $error = true; } else { if ($isadmin == 1) { if ($admin_password == "???") { $sqlInsert = "INSERT INTO login_users(username_email,password,IsAdmin) VALUES ('$user_email','$hashedPass','$isadmin')"; if(mysqli_query($conn,$sqlInsert)) { session_start(); header('Location: http://www.ramiwahdan.org/login.php', true); } else { die("Something went wrong"); } } else { $admin_password_error = "You entered the wrong Admin Password!"; $error = true; } } else { $sqlInsert = "INSERT INTO login_users(username_email,password,IsAdmin) VALUES ('$user_email','$hashedPass','$isadmin')"; if(mysqli_query($conn,$sqlInsert)) { session_start(); header('Location: http://www.ramiwahdan.org/login.php', true); } else { die("Something went wrong"); } } } } ?> in my login page I am checking if the entered password is the same as the one in my database but I am getting wrong password message, why is that? login.php: $test2 = 1; if($_SERVER["REQUEST_METHOD"] == "POST") { $myusername = mysqli_real_escape_string($db,$_POST['email']); $mypassword = mysqli_real_escape_string($db,$_POST['password']); $sql = "SELECT * FROM login_users WHERE username_email = '$myusername' and IsAdmin = $test2"; $result = mysqli_query($db, $sql); $count = mysqli_num_rows($result); if($count == 1) { // $row['password'] is hashed from the above register.php code while($row = $result->fetch_assoc()) { if (password_verify($mypassword, $row['password'])) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } } exit(); } } Why is that?
-
I found the issue. if I don't have a header redirect to main.php and move manually to main.php it will work. Why is that? here is the complete code: login.php <?php session_start(); //include("header.php"); include("config.php"); $myusername = ''; $mypassword = ''; $test2 = 1; $error=''; if($_SERVER["REQUEST_METHOD"] == "POST") { $myusername = mysqli_real_escape_string($db,$_POST['email']); $mypassword = mysqli_real_escape_string($db,$_POST['password']); $sql = "SELECT * FROM login_users WHERE username_email = '$myusername' and password = '$mypassword' and IsAdmin = $test2"; $result = mysqli_query($db, $sql); $count = mysqli_num_rows($result); if($count == 1) { $_SESSION['admin'] = $_POST['email']; print($_SESSION['admin']); //echo '<meta http-equiv="refresh" content="0;url=https://www.ramiwahdan.org/index.php">'; //header('Location: https://www.ramiwahdan.org/index.php', True); } else { $error = "Your login Name or Password is invalid"; $myusername=""; $mypassword=""; } } ?> <link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/> <link rel="stylesheet" href="register.css" type="text/css"> <div class="body-content"> <div class="module"> <div class="text-center"> <img src="2.png" width="90" height="90" class="rounded" alt=""> </div> <h1> Login User </h1> <form class="form" action="login.php" method="post" enctype="multipart/form-data" autocomplete="off"> <div class="alert alert-error"></div> <input type="text" placeholder="Email" name="email" required /> <input type="password" placeholder="Password" name="password" autocomplete="new-password" required /> <input type="submit" value="Login" name="login" class="btn btn-block btn-primary" /> <span id="error" style="color:red;font-weight:bold"><?= $error ?></span> </form> </div> </div> and main.php <?php session_start(); include("header.php"); print($_SESSION['admin']); if (!$_SESSION['admin']) { echo '<meta http-equiv="refresh" content="0;url=https://www.ramiwahdan.org/login.php">'; } ?> so commenting out the header in login.php, I will be able to browse to main.php after logging-in and everything is fine. when un commenting the header, it won't!
-
Hi I am trying to access a session variable from one page to another but it is not working and yes, the IONOS is allowing sessions. here is the code: login.php: $sql2 = "SELECT * FROM login_users WHERE username_email = '$myusername' and password = '$mypassword' and IsAdmin = 1"; $result2 = mysqli_query($db, $sql2); $count2 = mysqli_num_rows($result2); if($count2 == 1) { $_SESSION['admin'] = $myusername; header('Location: https://www.ramiwahdan.org/main.php', True); } else { $error = "Your login Name or Password is invalid"; $myusername=""; $mypassword=""; } and main.php: <?php session_start(); $myusername = $_SESSION['admin']; print($myusername); ?> why is that? I am not getting any errors.
-
Hi, I have this code that I am trying to check between 2 dates. the first date taken from DB abd the second date is currect date. I want to compare between them (how many days left, it is not working. <?php include('connect.php'); $sqlSelect = "select dueDate as date from subscriptions"; $result = mysqli_query($conn,$sqlSelect); $date = new DateTime(date('d-m-Y H:i:s')); while($data = mysqli_fetch_array($result)) { $diff=date_diff($date,$data["date"]); if( $data["date"] > $date && $diff < 15) { print("ok"); } } ?> How to go about this?