Jump to content

[SOLVED] multi-level user login system not working


coldfiretech

Recommended Posts

For some reason this wont work with the top bit of code so i had to comment it out.. Everything else works but the commented code.  When i try to login with a fresh user it just sits at a blank page and doesnt do anything...

 

Im not sure what is going on.. Any help would be greatly appreciated ;)

Thanks  ;D ;D

 

 


<?php
session_start(); 

$loggedin = $_COOKIE['loggedin'];
$subtype = $_COOKIE['subtype'];

//if ($loggedin=="yes") {
//	echo "you are already logged in";
//	// redirect to correct panel
//	  if ($subtype=="single") {
//		print "<META HTTP-EQUIV=\"refresh\" content=\"2; URL=/cellsavior/single_plan_panel.php\">";
//				} 
//	
//		if ($subtype=="partner") {
//			print "<META HTTP-EQUIV=\"refresh\" content=\"2; URL=/cellsavior/partner_plan_panel.php\">";
//				} 
//
//		if ($subtype=="family") {
//				print "<META HTTP-EQUIV=\"refresh\" content=\"2; URL=/cellsavior/family_plan_panel.php\">";
//
//	} else {  
//do login
$db_host = 'localhost';
$db_user = '******;
$db_pass = '*****;
$db_db = '*******';
$con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error());
mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table');

$user = mysql_real_escape_string($_POST['login']);
$password = mysql_real_escape_string($_POST['password']);
$sid = $_POST['login'];
$q = "
SELECT 
	login, subtype, id
FROM `users`
Where
	login = '".$user."' AND 
	password = '".$password."'
";
$r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q);
if(mysql_num_rows($r) >0){
$row = mysql_fetch_assoc($r);
$_SESSION['login'] = $sid; // store session data
setcookie("loggedin", "yes");

	switch ($row['subtype']){

	case "single":

		setcookie("subtype", "single");
			die(header("location: /cellsavior/single_plan_panel.php"));

	break;
		case "partner":

			setcookie("subtype", "partner");
				die(header("location: /cellsavior/partner_plan_panel.php"));

	break;
		case "family":

			setcookie("subtype", "family");
				die(header("location: /cellsavior/family_plan_panel.php"));

	break;
		default:
			die(header("location: index.html?msg=invalid subtype"));

				if(isset($_SESSION['login']))
    				unset($_SESSION['login']); 
				setcookie("loggedin", "", time()-3600);

	}
}
else{

die(header("location: index.html?msg=invalid login"));

				if(isset($_SESSION['login']))
    				unset($_SESSION['login']);
    				setcookie("loggedin", "", time()-3600);
    				
		}
mysql_close ($con);
//}
//}
?>

Try this:

if ($loggedin=="yes") {
echo "you are already logged in";
// redirect to correct panel
  if ($subtype=="single") {
	header("Location: /cellsavior/single_plan_panel.php");
			} 

	if ($subtype=="partner") {
		header("Location: /cellsavior/partner_plan_panel.php");
			} 

	if ($subtype=="family") {
			header("Location: /cellsavior/family_plan_panel.php");

} else {  
do login

Thanks  i have changed my code to this and now nothing works.

 

The errors i get are

Notice: Undefined index: loggedin in C:\wamp\www\cellsavior\userAuth2.php on line 5

 

Notice: Undefined index: subtype in C:\wamp\www\cellsavior\userAuth2.php on line 6

 

<?php
ini_set('display_errors','On');
error_reporting(E_ALL);   
session_start(); 
$loggedin = $_COOKIE['loggedin'];
$subtype = $_COOKIE['subtype'];
if ($loggedin=="yes") {
echo "you are already logged in";
// redirect to correct panel
  if ($subtype=="single") {
	header("Location: /cellsavior/single_plan_panel.php");
			} 
		if ($subtype=="partner") {
		header("Location: /cellsavior/partner_plan_panel.php");
			} 
	if ($subtype=="family") {
			header("Location: /cellsavior/family_plan_panel.php");
} else {  
//do login
$db_host = 'localhost';
$db_user = '****';
$db_pass = '********';
$db_db = '*******';
$con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error());
mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table');
$user = mysql_real_escape_string($_POST['login']);
$password = mysql_real_escape_string($_POST['password']);
$sid = $_POST['login'];
$q = "
SELECT 
	login, subtype, id
FROM `users`
Where
	login = '".$user."' AND 
	password = '".$password."'
";
$r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q);
if(mysql_num_rows($r) >0){
$row = mysql_fetch_assoc($r);
$_SESSION['login'] = $sid; // store session data
setcookie("loggedin", "yes");
 		switch ($row['subtype']){
		case "single":
			setcookie("subtype", "single");
				die(header("location: /cellsavior/single_plan_panel.php"));
	break;
		case "partner":
			setcookie("subtype", "partner");
				die(header("location: /cellsavior/partner_plan_panel.php"));			
	break;
		case "family":

			setcookie("subtype", "family");
				die(header("location: /cellsavior/family_plan_panel.php"));	
	break;
		default:
			die(header("location: /cellsavior/index.html?msg=invalid subtype"));

				if(isset($_SESSION['login']))
    				unset($_SESSION['login']); 
				setcookie("loggedin", "", time()-3600);	
	}
}
else{

die(header("location: /cellsavior/index.html?msg=invalid login"));
				if(isset($_SESSION['login']))
    				unset($_SESSION['login']);
    				setcookie("loggedin", "", time()-3600);			
		}
mysql_close ($con);
}
}
?>

count the opening and closing braces.  see anything wrong?

 

if ($loggedin=="yes") {
echo "you are already logged in";
// redirect to correct panel
  if ($subtype=="single") {
	header("Location: /cellsavior/single_plan_panel.php");
			} 
		if ($subtype=="partner") {
		header("Location: /cellsavior/partner_plan_panel.php");
			} 
	if ($subtype=="family") {
			header("Location: /cellsavior/family_plan_panel.php"); // <-- HOW ABOUT RIGHT HERE?
} else {  

 

you're missing a closing brace on that third if().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.