Jump to content


Photo

stupid thing doesnt wanna work. :( any help is helpful please.


  • Please log in to reply
7 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 26 August 2006 - 07:30 AM

<?php
session_start();
$action = $_GET['action'];
// *** If the action is login or default? ***
if ( $action == login || $action == '' ) { 

	if ($logged_in = 1) 
	{
	echo $logged_in;
	echo '<meta http-equiv="Refresh" Content="5; URL=modules.php?name=cpanel&action=profile">';
	} 	
	else if ($logged_in = 0) 
	{

// Begin Login Code

		if(isset($_POST['login'])) 
		{
		   $error = '';
		   $username = $_POST['username'];
		   $password = $_POST['password'];
		   
		   if(!isset($username) || !isset($password)) 
		   {
		   $error .= 'A required field was left blank.<br />';
		   }
 			  $password = md5($password);
			 
			  if(get_magic_quotes_gpc()) 
			  {
		      $username = $username;
		      } 
		      else 
		      {
		      $username = addslashes($username); 
		      }
		      
		   $result = $libmysql->query("SELECT * FROM $table_users WHERE alias='$username' AND password='$password'");
		   $valid_login = mysql_num_rows($result);
		
		   if($valid_login == 0) 
		   {
	       $error .= 'The supplied username and/or password was incorrect.<br />';
    	   }
    	   
   		   if($error == '') 
   		   {
      	   $data = mysql_fetch_array($result);
		   $_SESSION['username'] = $data['username'];
      	   $libmysql->query("UPDATE `$table_users` SET last_seen='$date' WHERE alias='$username'");
           $logged_in = 1;
           echo '<meta http-equiv="Refresh" Content="0; URL=modules.php?name=cpanel&action=profile">';
           die();
   	  	   } 
	       else 
		   {
	       echo 'The following errors were returned:<br />'.$error.'<br />';
   		   }
		}

// Echo Module Data
		   $query = $libmysql->query("SELECT * FROM $table_modules WHERE title='login'");
	       $row = $libmysql->fetch_array($query);

		   $data = $row['data'];
		   echo $data;
		   $libmysql->free_result($query);
		   }   
		   
// *** If the action is profile (user logged in)? *** 
} else if ( $action == profile ) {

	if(isset($_SESSION['username']) || $logged_in = 1) 
	{
	$ses_user = $_SESSION['username'];

	// Echo Module Data
	$query = $libmysql->query("SELECT * FROM $table_modules WHERE title='cpanel'");
    $row = $libmysql->fetch_array($query);
    $info = $row['data'];
    
    $query2 = $libmysql->query("SELECT * FROM $table_users WHERE alias='$ses_user'");
    $row2 = $libmysql->fetch_array($query2);
    $signup_date = $row2['signup_date'];
	$last_seen = $row2['last_seen'];

    $session_id = session_id();    
    $loginmsg = "You are logged in, $ses_user <br /><br />Your last log in was $last_seen <br /><br />You registered $signup_date<br /><br />";

    echo $loginmsg;
    echo "<br /><br />$info";
    echo "Your session id is: $session_id";
    echo "<br /><br /><br />";
    echo "<a href='modules.php?name=cpanel&action=logout'>Click here to logout</a>";
    $libmysql->free_result($query);
	} 
	else
	{
    echo "You aren't logged in.<br /><br />Please <a href='modules.php?name=signup'>register</a> or <a href='modules.php?name=login'>log in.</a>";
    }


// Logout Page
} else if ( $action == logout ) { 
$logged_in = 0;
$_SESSION = array();
echo '<meta http-equiv="Refresh" Content="0; URL=index.php">';
echo 'You have been logged out, you are being redirected...';
die();
}
?>

can someone help me figure out why it does log in and out properly.

#2 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 26 August 2006 - 07:37 AM

First off try taking out the $logged_in = ''; out of it.. 'cause you've got it over-writing anything thats stored in the variable...  try that if it doesnt work come back and let us know whats actually happening.. 

#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 26 August 2006 - 07:40 AM

ok

#4 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 26 August 2006 - 07:51 AM

Though me personally -- since the $logged_in has nothing to do with the database or the session i would totally remove that and just check to see if the session variable is written.. if it is then redirect -- if not show the login form..  that'd be the easiest way to do it..  otherwise it may never work...

#5 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 26 August 2006 - 07:52 AM

nope doesnt work, i cleaned the code up a bit more. i echo'd the output of $logged_in variable and it gave me logged_in = 1, even when i went to &action=logout page. when i go to the &profile page it says this:

You are logged in,

Your last log in was

You registered



asdf? works :DYour session id is: 3b2c7c1419be1c0626176260ae85831d


Click here to logout


its suppose to say you are logged in, username. your last login was today, u registered whatenver, etc... like that but its not.

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 26 August 2006 - 07:53 AM

Though me personally -- since the $logged_in has nothing to do with the database or the session i would totally remove that and just check to see if the session variable is written.. if it is then redirect -- if not show the login form..  that'd be the easiest way to do it..  otherwise it may never work...


ok will try totally removing the $logged_in variable.

#7 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 26 August 2006 - 08:02 AM

ok great i removed the logged_in variable and it works almost perfectly except whenever someone goes to the &action=profile page and theyre not logged in, it just says this instead of giving them an error message denying their access and saying theyre not logged in:

You are logged in,

Your last log in was

You registered



asdf? works :DYour session id is: 3b2c7c1419be1c0626176260ae85831d


Click here to logout


here's the new updated code by the way. can anyone please fix??

<?php
session_start();
$action = $_GET['action'];
$date = date("F j, Y, g:i a");  
// *** If the action is login or default? ***
if ( $action == login || $action == '' ) { 

// Begin Login Code

		if(isset($_POST['login'])) 
		{
		   $error = '';
		   $username = $_POST['username'];
		   $password = $_POST['password'];
		   
		   if(!isset($username) || !isset($password)) 
		   {
		   $error .= 'A required field was left blank.<br />';
		   }
 			  $password = md5($password);
			 
			  if(get_magic_quotes_gpc()) 
			  {
		      $username = $username;
		      } 
		      else 
		      {
		      $username = addslashes($username); 
		      }
		      
		   $result = $libmysql->query("SELECT * FROM $table_users WHERE alias='$username' AND password='$password'");
		   $valid_login = mysql_num_rows($result);
		
		   if($valid_login == 0) 
		   {
	       $error .= 'The supplied username and/or password was incorrect.<br />';
    	   }
    	   
   		   if($error == '') 
   		   {
      	   $data = mysql_fetch_array($result);
		   $_SESSION['username'] = $data['username'];
      	   $libmysql->query("UPDATE `$table_users` SET last_seen='$date' WHERE alias='$username'");
           echo '<meta http-equiv="Refresh" Content="0; URL=modules.php?name=cpanel&action=profile">';
           die();
   	  	   } 
	       else 
		   {
	       echo 'The following errors were returned:<br />'.$error.'<br />';
   		   }
		}

// Echo Module Data
		   $query = $libmysql->query("SELECT * FROM $table_modules WHERE title='login'");
	       $row = $libmysql->fetch_array($query);

		   $data = $row['data'];
		   echo $data;
		   $libmysql->free_result($query);
		   
		   
// *** If the action is profile (user logged in)? *** 
} else if ( $action == profile ) {

	if(isset($_SESSION['username'])) 
	{
	$ses_user = $_SESSION['username'];

	// Echo Module Data
	$query = $libmysql->query("SELECT * FROM $table_modules WHERE title='cpanel'");
    $row = $libmysql->fetch_array($query);
    $info = $row['data'];
    
    $query2 = $libmysql->query("SELECT * FROM $table_users WHERE alias='$ses_user'");
    $row2 = $libmysql->fetch_array($query2);
    $signup_date = $row2['signup_date'];
	$last_seen = $row2['last_seen'];

    $session_id = session_id();    
    $loginmsg = "You are logged in, $ses_user <br /><br />Your last log in was $last_seen <br /><br />You registered $signup_date<br /><br />";

    echo $loginmsg;
    echo "<br /><br />$info";
    echo "Your session id is: $session_id";
    echo "<br /><br /><br />";
    echo "<a href='modules.php?name=cpanel&action=logout'>Click here to logout</a>";
    $libmysql->free_result($query);
	} 
	else
	{
    echo "You aren't logged in.<br /><br />Please <a href='modules.php?name=signup'>register</a> or <a href='modules.php?name=login'>log in.</a>";
    }


// Logout Page
} else if ( $action == logout ) { 
$_SESSION = array();
echo '<meta http-equiv="Refresh" Content="0; URL=index.php">';
echo 'You have been logged out, you are being redirected...';
die();
}
?>


#8 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 26 August 2006 - 08:09 AM

nevermind fixed it. thanks all for the help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users