Jump to content

Archived

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

newb

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

Recommended Posts

[code]
<?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();
}
?>
[/code]

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

Share this post


Link to post
Share on other sites
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.. 

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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:

[quote]
You are logged in,

Your last log in was

You registered



asdf? works :DYour session id is: 3b2c7c1419be1c0626176260ae85831d


Click here to logout[/quote]

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

Share this post


Link to post
Share on other sites
[quote author=radar link=topic=105680.msg422250#msg422250 date=1156578719]
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...
[/quote]

ok will try totally removing the $logged_in variable.

Share this post


Link to post
Share on other sites
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:

[quote]
You are logged in,

Your last log in was

You registered



asdf? works :DYour session id is: 3b2c7c1419be1c0626176260ae85831d


Click here to logout
[/quote]

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

[code]
<?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();
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.