spInGoBlin Posted April 26, 2006 Share Posted April 26, 2006 I'm trying to separate some users (with admin rights) from others, so that they can view and enter some data that will be hidden from others in many consequent windows. My login page goes like this:if (isset($_POST['Submit'])){ $username = $_POST['username']; $password = $_POST['password']; $result = mysql_query("Select * From admin where username='$username'",$link); if(mysql_num_rows($result)>0) { $row = mysql_fetch_array($result, MYSQL_BOTH); if($password == $row["password"]) { $_SESSION['adminok'] = "ok"; $_SESSION['username'] = "username"; $_SESSION['password'] = "password"; header("Location: admin.php"); } else {$msg = "Password incorrect";} } else {$msg = "Username incorrect";}}?>There's a row in the SQL table (admin_rights) that's either 0 or 1 (true/false). how can I pass this variable on to another php page to filter out some rows from other SQL tables, depending on this variable? I reckon it should go something like this:$clientsresult = mysql_query("Select * from clients",$link);$numcli = mysql_num_rows($clientsresult);$nc = 0; while($clients = mysql_fetch_array($clientsresult, MYSQL_BOTH)){ [b]if ($isadmin) {[/b] $nc++; $client[$clients['client_ID']] = $clients['name']; } }Well, this seems simple, but how shall I get the [b]$isadmin[/b] from login page? This is also simple I know :) but I'm having awsome trouble. Help please! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/8508-please-help-with-cross-file-variables-admin-login-options/ Share on other sites More sharing options...
Twentyoneth Posted April 27, 2006 Share Posted April 27, 2006 [EDIT: Misread. ] Quote Link to comment https://forums.phpfreaks.com/topic/8508-please-help-with-cross-file-variables-admin-login-options/#findComment-31195 Share on other sites More sharing options...
sanfly Posted April 27, 2006 Share Posted April 27, 2006 Cant you just add a session in the login page? Or am i misreading too?[code]if (isset($_POST['Submit'])){$username = $_POST['username'];$password = $_POST['password'];$result = mysql_query("Select * From admin where username='$username'",$link);if(mysql_num_rows($result)>0){$row = mysql_fetch_array($result, MYSQL_BOTH);if($password == $row["password"]){$_SESSION['isadmin'] = "1"; // 1 = yes, 0 = no$_SESSION['adminok'] = "ok";$_SESSION['username'] = "username";$_SESSION['password'] = "password";header("Location: admin.php");}else {$msg = "Password incorrect";}}else {$msg = "Username incorrect";}}?>[/code]then in the other page[code]$clientsresult = mysql_query("Select * from clients",$link);$numcli = mysql_num_rows($clientsresult);$nc = 0;while($clients = mysql_fetch_array($clientsresult, MYSQL_BOTH)){if ($_SESSION['isadmin'] == "1") {$nc++;$client[$clients['client_ID']] = $clients['name'];}}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8508-please-help-with-cross-file-variables-admin-login-options/#findComment-31200 Share on other sites More sharing options...
spInGoBlin Posted April 27, 2006 Author Share Posted April 27, 2006 Thank You sanfly! It worked perfectly, after I remembered to use start_session(), too :) Problem solved Quote Link to comment https://forums.phpfreaks.com/topic/8508-please-help-with-cross-file-variables-admin-login-options/#findComment-31219 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.