Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

A basic login to go with my registration

Featured Replies

LOGIN.PHP

 


<?php
session_start();
include("config.php");
connect();

$username = protect($_POST['username']);
$pass = md5($_POST['pass']);

//make sure pass and username are not blank
if(isset($_POST['submit'])){
if(trim($_POST['username']) == '' || $_POST['pass'] == ''){

echo"<center><p>I am sorry both password and username must be filled out</p></center>";

}else{
// check if pass and username are in database
$sql1 = "SELECT pass,uid FROM users WHERE uid = '".$username."' AND pass ='".$pass."'";
$sql2 = mysql_query($sql1) or die (mysql_error());
if(mysql_num_rows($sql2) == 0){

echo"<center><p>Your username or password are incorrect</p></center>";

}else{
$member =mysql_fetch_assoc($sql2);

$_SESSION['uid'] = $member['uid'];
mysql_close();
header("Location:members.php");

}



}


}
if(!isset($_POST['submit'])){

echo "<form method=\"POST\" action=\"login.php\">";
echo "<p><b>Username:</b> <input type=\"text\" name=\"username\"></p>";
echo "<p><b>Password:</b> <input type=\"password\" name=\"pass\"></p>";
echo "<p> <input type=\"submit\" name=\"submit\" value=\"Login\"></p>";
echo "</form>";
}





?>


 

MEMBERS.PHP

 

<?php
session_start();
//Check if session exist
if(!$_SESSION['uid']){
echo "<center>
<p>
Welcome guest you currently are not logged in <a href=\"register.php\">Register</a>-Or-<a href=\"login.php\">Login</a>
</p>
</center>";
}else{
echo "<center>
<p>
Welcome ".$_SESSION['uid']." <a href=\"logout.php\">Logout</a>
</p>
</center>";
}

?>

 

LOGOUT.PHP

 

 

<?php
session_start();
if($_SESSION['uid']){
session_destroy();
header("Location:login.php");
}
?>

You're not checking/sanitising $username before passing it to the query.

 

Also, you're assuming that $_SESSION['uid'] is valid in members.php - sessions can be forged across domains (so it's uncommon, but not impossible). See: http://sla.ckers.org/forum/read.php?4,22496

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.