Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-05-2008, 04:52 PM PHP Login
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Hello!

Mgraphic wrote this for me about a year ago, however I've only just used it and it appears to be problematic.

It isn't logging in! It checks if the username and password are fine, but doesn't set the session to remain logged in. Any suggestions?

PHP Code:
function check_login($username$password$required 0$redirect "http://www.siteurl.com/login.php")
{
  if (isset(
$_SESSION['user']) && isset($_SESSION['pass'])) return true;
  if (!empty(
$username) && !empty($password))
  {
    
$username stripslashes($username);
    
$password stripslashes($password);
    
$checkq mysql_query("
      SELECT `username`, `password`
      FROM `accounts`
      WHERE
        `username` = '" 
$username "'
        AND `password` = '" 
md5($password) . "'
      LIMIT 1
    "
);
    if (
mysql_num_rows($checkq) > 0)
    {
      
$session_backup $_SESSION;
      unset(
$_COOKIE[session_name()]);
      
session_destroy();
      
session_start();
      
$_SESSION $session_backup;
      unset(
$session_backup);
      
      
$user_row mysql_fetch_assoc($checkq);
      
$_SESSION['user'] = $user_row['username'];
      
$_SESSION['pass'] = $user_row['password'];
      unset(
$user_row);
      
      return 
true;
    }
  }
  if (
$required == 1)
  {
    
header("location: $redirect");
    exit();
  }
  return 
false;

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 08-05-2008, 05:15 PM Re: PHP Login
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I sure don't remember writing this, but check if $_SESSION['user'] and $_SESSION['pass'] is set and holds a value for each. If so, it should be logged in.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-05-2008, 05:21 PM Re: PHP Login
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Seems they are not being set. Cannot understand why though.

And yes you did write it, I found it in my PHP Login Function post about a year ago
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 08-05-2008, 06:12 PM Re: PHP Login
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Can you include the script that calls this function?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-05-2008, 07:41 PM Re: PHP Login
vn5ltr's Avatar
Skilled Talker

Posts: 93
Location: Melbourne, Australia
Trades: 0
Try calling session_start() before anything
vn5ltr is offline
Reply With Quote
View Public Profile
 
Old 08-06-2008, 02:55 AM Re: PHP Login
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
It's not setting the session. I have session_start(); at the top of all things also.

I shoved it in the config. The only code to it is:

PHP Code:
function check_login($username$password$required 0$redirect "http://www.bestadboard.com/login.php")
{
  if (isset(
$_SESSION['user']) && isset($_SESSION['pass'])) return true;
  if (!empty(
$username) && !empty($password))
  {
    
$username stripslashes($username);
    
$password stripslashes($password);
    
$checkq mysql_query("
      SELECT `username`, `password`
      FROM `accounts`
      WHERE
        `username` = '" 
$username "'
        AND `password` = '" 
md5($password) . "'
      LIMIT 1
    "
);
    if (
mysql_num_rows($checkq) > 0)
    {
      
$session_backup $_SESSION;
      unset(
$_COOKIE[session_name()]);
      
session_destroy();
      
session_start();
      
$_SESSION $session_backup;
      unset(
$session_backup);
      
      
$user_row mysql_fetch_array($checkq);
      
$_SESSION['user'] = $user_row['username'];
      
$_SESSION['pass'] = $user_row['password'];
      unset(
$user_row);
      
      return 
true;
    }
  }
  if (
$required == 1)
  {
    
header("location: $redirect");
    exit();
  }
  return 
false;
}

if(
check_login()){
$user mysql_fetch_array(mysql_query("select * from accounts where id = '".$_SESSION['user']."' limit 1"));
die(
$user['username']);
$loggedin true;

and the login.php is

PHP Code:
if($loggedin == true) {
header("location:$siteurl");
}

if(
check_login($_POST['username'], $_POST['password'])) {
header("location: account.php");

It's kind of annoying because I wanted to use this function instead of my "overdone" version :P
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!


Last edited by Galaxian; 08-06-2008 at 02:56 AM..
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 08-06-2008, 03:59 AM Re: PHP Login
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Heh, I messed around and managed to get it working. Dunno what the retarded mistake on my part was.

Sorry for wasting ya' time ^^
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 08-06-2008, 11:29 PM Re: PHP Login
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by Galaxian View Post
Heh, I messed around and managed to get it working. Dunno what the retarded mistake on my part was.

Sorry for wasting ya' time ^^
I'm glad you got it going, I'm still not sure where the problem was...

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Login
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.66257 seconds with 12 queries