Pikachu2000 Posted January 29, 2012 Share Posted January 29, 2012 You need to enable error reporting at its highest level. In your php.ini file, find the following directives, and set them as below. Then restart Apache, run the script again and see what, if any, errors are reported. error_reporting = -1 display_errors = On Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312340 Share on other sites More sharing options...
Drummin Posted January 29, 2012 Share Posted January 29, 2012 Have you checked that session is being set? If not try this. if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ // header("location:login_success.php"); // exit; } if($_SESSION['U_YearID']==2){ // header("location:login_success2.php"); // exit; } if($_SESSION['U_YearID']==4){ // header("location:login_success4.php"); // exit; } echo "$_SESSION[u_YearID]"; } else { echo "Wrong Username or Password"; } If you are getting results as expected with values being echoed (1, 2 or 4) then try this code. Brackets added around IF statements with exit added. if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } } else { echo "Wrong Username or Password"; } Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312341 Share on other sites More sharing options...
jusjus7 Posted January 29, 2012 Author Share Posted January 29, 2012 no all i keep getting is a blank page :/ Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312347 Share on other sites More sharing options...
jusjus7 Posted January 29, 2012 Author Share Posted January 29, 2012 You need to enable error reporting at its highest level. In your php.ini file, find the following directives, and set them as below. Then restart Apache, run the script again and see what, if any, errors are reported. error_reporting = -1 display_errors = On this is what i have found error_reporting ; Default Value: E_ALL & ~E_NOTICE ; Development Value: E_ALL | E_STRICT ; Production Value: E_ALL & ~E_DEPRECATED is this what i need to change? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312349 Share on other sites More sharing options...
Drummin Posted January 29, 2012 Share Posted January 29, 2012 You need to use table fields as in $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; NOT $sql="SELECT * FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312350 Share on other sites More sharing options...
jusjus7 Posted January 29, 2012 Author Share Posted January 29, 2012 You need to use table fields as in $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; NOT $sql="SELECT * FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; That is what i am using $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; <?php session_start(); ini_set('session.bug_compat_42',0); ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; //echo $sql; $result=mysql_query($sql); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312351 Share on other sites More sharing options...
jusjus7 Posted January 29, 2012 Author Share Posted January 29, 2012 all i get is a blank page back! Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312352 Share on other sites More sharing options...
Drummin Posted January 29, 2012 Share Posted January 29, 2012 Have you echoed out the session to see if it's being set? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312355 Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2012 Share Posted January 29, 2012 The leading semicolon indicates a comment, so you need to find the line that isn't commented for each of the directives, and set those as above. That should be where you keep those values set while developing. Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312360 Share on other sites More sharing options...
jusjus7 Posted January 29, 2012 Author Share Posted January 29, 2012 Have you echoed out the session to see if it's being set? yes i did and nothing still got blank page Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312363 Share on other sites More sharing options...
jusjus7 Posted January 29, 2012 Author Share Posted January 29, 2012 The leading semicolon indicates a comment, so you need to find the line that isn't commented for each of the directives, and set those as above. That should be where you keep those values set while developing. so one of the semicolons is wrongly placed? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312364 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 Add error reporting to the top of your page. Maybe that will shed some light. <?php session_start(); error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312365 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Add error reporting to the top of your page. Maybe that will shed some light. <?php session_start(); error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); nope nothing happens it just gives me a blank checklogin.php page :/ could it be the if statements are not properly written? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312367 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Add error reporting to the top of your page. Maybe that will shed some light. <?php session_start(); error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); nope nothing happens it just gives me a blank checklogin.php page :/ could it be the if statements are not properly written? as i took off the error reporting thing you said this has come up again :/ Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0 Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312368 Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 The leading semicolon indicates a comment, so you need to find the line that isn't commented for each of the directives, and set those as above. That should be where you keep those values set while developing. so one of the semicolons is wrongly placed? No, not necessarily. If, and only if, there is no line with error_reporting = [some value], without a semicolon preceding it, add the line as above. If there is a line with no semicolon, just change the value. Same goes for display_errors. Then save the file and restart Apache. Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312369 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 How about some simple testing to see if query is working. <?php session_start(); //ini_set('session.bug_compat_42',0); //ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //Add isset if (isset($_POST['UsersID'])){ //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; //echo $sql; $result=mysql_query($sql); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" /* $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } */ echo "{$result[1]}"; } else { echo "Wrong Username or Password"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312370 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 How about some simple testing to see if query is working. <?php session_start(); //ini_set('session.bug_compat_42',0); //ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //Add isset if (isset($_POST['UsersID'])){ //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; //echo $sql; $result=mysql_query($sql); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" /* $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } */ echo "{$result[1]}"; } else { echo "Wrong Username or Password"; } } ?> hmm it doesnt seem to be working as i still get a blank page :/ so its the query :s Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312373 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 but when i put a wrong username or password it does tell me its wrong!! Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312374 Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 And when you put in a correct password and username, you get a blank screen? What happens to the URL in the address bar? Does it stay the same, or does it change? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312375 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 And when you put in a correct password and username, you get a blank screen? What happens to the URL in the address bar? Does it stay the same, or does it change? it changes to the checklogin2.php address Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312376 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 And your DB table users has the field called `U_YearID`? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312377 Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 Then that's where the error is, in the checklogin2.php script. Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312378 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 And your DB table users has the field called `U_YearID`? yep # Column Type Collation Attributes Null Default Extra Action 1 UsersID varchar(7) latin1_swedish_ci No None Change Drop More 2 U_Password varchar(10) latin1_swedish_ci No None Change Drop More 3 U_YearID varchar(1) latin1_swedish_ci No None Change Drop More 4 U_FirstName tinytext latin1_swedish_ci No None Change Drop More 5 U_LastName tinytext latin1_swedish_ci No None Change Drop More 6 CompanyID Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312379 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Then that's where the error is, in the checklogin2.php script. yep but i cant seem to figure out where i have been looking at this code all day and nothing seems to look wrong (to me) <?php session_start(); ini_set('session.bug_compat_42',0); ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; //echo $sql; $result=mysql_query($sql); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ header("Location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("Location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("Location:login_success4.php"); exit; } } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312380 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 Is the name of the page we're working on called checklogin2.php? Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/2/#findComment-1312381 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.