0

I want to make option to approve users before they can login or to ban them, here is code

MySQL Syntax (Toggle Plain Text)
<HTML><HEAD><TITLE>Fakultet informacionih tehnologija</TITLE> </HEAD>
 
<BODY TEXT="#ffffff" BACKGROUND="fakultet/Assets/bg.jpg" LINK="#FFFF00" VLINK="#CDCD00" BGCOLOR="#000000">
 
 
 
<CENTER><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="700">
 
 
 
 
 
<CENTER>
 
  <FONT SIZE=+4 FACE="arial,helvetica">
 
    Fakultet informacionih tehnologija
 
 
    <HR>
 
</CENTER>
 
<?php
session_start();
// dBase file
include "dbConfig.php";
 
if ($_GET["op"] == "login")
 {
 if (!$_POST["username"] || !$_POST["password"])
  {
	header("Refresh: 3;login.php");
  die("You need to provide a username and password.");
	}
 
 
 
 // CREATE query
 $q = "SELECT * FROM `dbUsers` "
  ."WHERE `username`='".$_POST["username"]."' "
  ."AND `password`=PASSWORD('".$_POST["password"]."') "
  ."LIMIT 1";
 
 // Run query
 $r = mysql_query($q);
 
 
 if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, CREATE session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = TIME();
 
  // Redirect to member page
  Header("Location: index.php");
  }
 ELSE
  {
// Login NOT successful
header('Refresh: 3;login.php');
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=\"POST\">";
 echo "Username: <input name=\"username\" size=\"15\"><br />";
 echo "Password: <input type=\"password\" name=\"password\" size=\"16\"><br />";
 echo "<input type=\"submit\" value=\"Login\"><br />";
 echo "<a href=\"register.php\">Register</a>";
 echo "</form>";
 }
?>
 
<br><FONT SIZE=+3>Coded BY Filip ^_^</A></FONT>
 
</BODY></HTML>

and in sql dbusers I have tabs id,user,password,email,approved and banned. So what code I need to add into php to make check for approved/banned?

3
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by filipgothic
1
if ( $obj = @mysql_fetch_object($r) )  {
  if($obj->approved == 1 && !$obj->banned) {
    // Login good, CREATE session variables
    $_SESSION["valid_id"] = $obj->id; 
    $_SESSION["valid_user"] = $_POST["username"];  
    $_SESSION["valid_time"] = TIME();   
    // Redirect to member page  Header("Location: index.php");
  }
  else
    echo "user not approved or has been banned!";
}
Votes + Comments
thanks!
0

thanks for reply, I tried first editing login good code and had errors, now I added ur code in difrent section and is good but wont log me in if approved is 1

Edited by filipgothic: n/a

0

the session will throw an error if there is content being outputted before it get's started, try putting the session on the first line.

0

to add this code after session start or to move exsisting one already with just new line?

if($obj->approved == 1 && !$obj->banned) {

}

Edited by filipgothic: n/a

0

all you need is to add the session start at the very beginning ex:

<?php session_start(); ?>

<!-- your markup here -->

<?php 
if($obj->approved == 1 && !$obj->banned) {
     //more code
} 
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.