Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Redirect Depending On User Type
    primarykey
    data
    text
    <p>I have a login page that fairly basic. I'm developing a prototype whilst learning the in's and outs of PHP.</p> <p>In my MySql database, it looks like this: UserID, username, passcode, talent, customer. Talent and customer are both binary and only one can be True.</p> <p>So what I'm trying to do, is if talent = 1, send them to index.php, and if customer = 1, send them to recruiter.php.</p> <p>I'm 90% sure I have the basics down, but since I've added the extra if's to check talent and customer, it's broken my script :)</p> <p>Finally, I'd need to do this check on each page to make sure that customers don't access talent pages and visa versa. </p> <p>Am I on the right track??</p> <p>My current script does this:</p> <pre><code> &lt;?php include("resource/config.php"); if($_SERVER["REQUEST_METHOD"] == "POST") { // username and password sent from Form $myusername=addslashes($_POST['username']); $mypassword=addslashes($_POST['password']); $sql="SELECT UserID, talent, customer FROM useradmin WHERE username='$myusername' and passcode='$mypassword'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); $active=$row['active']; $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if ($row['talent']==1) { if ($count==1) { $_SESSION['login_user']=$myusername; header("location: index.php"); } else { $error="Your Email or Password is invalid"; } } elseif ($row['customer']==1) { if ($count==1) { $_SESSION['login_user']=$myusername; header("location: recruiter.php"); } else { $error="Your Email or Password is invalid"; } } else { $error="Your Login Name or Password is invalid"; } } ?&gt; </code></pre> <p>Also, at the top of every page I have this, to make sure only a logged in user can access it.</p> <pre><code>&lt;?php session_start(); include('config.php'); $user_check=$_SESSION['login_user']; $ses_sql=mysql_query("select username from useradmin where username='$user_check' "); $row=mysql_fetch_array($ses_sql); $login_session=$row['username']; if(!isset($login_session)) { header("Location: login.php"); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload