Jump to content


Photo

OOP Problems with Login Handling class


  • Please log in to reply
3 replies to this topic

#1 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 22 September 2006 - 01:21 AM

Okay so I have this file set up with my log in function:

<?php

class LogIn {

var $username;
var $password;
var $referer;
    function siteLogin()
    {
        // connect to the server
        $conn = @mysql_connect("this", "is", "private")
        or die('Could not connect to mySQL.');
        if ((!$username) or (!$password)) {
            header("location:$referer");
            exit();
        }
        // select a database
        $rs = mysql_select_db("snapskate", $conn);
        // put up the mysql query
        $sql = "select * from users where username=\"$username\" and password=\"$password\"";
        // now put the query execution in a variable so we can use it later
        $rs = @mysql_query($sql, $conn);
        // now see how many rows come up with a match.
        $num = mysql_num_rows($rs);
        // if it came up as one or more, log the user in
        if ($num != null) {
            setcookie('loggedin', '1', time() + 36000);
            setcookie('username', $username, time() + 36000);
            $msg = "<table cellpadding=\"20\">";
            $msg .= "<tr><td class=\"inout\" valign=\"middle\" align=\"center\">";
            $msg .= "Thank You.  You are now logged in as $username. <br />You are now being transferred.<br /><br />";
            $msg .= "<a href=\"http://www.snapskate.com/index.php\">Click here if you do not wish to wait</a>";
            $msg .= "</tr></td></table>";
            echo($msg);
            echo("<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"2;URL=http://www.snapskate.com/\">");
        } else {
            sleep(2);
            header("location:$referer");
            exit();
        }
    }
}

?>

and this file (authenticate.php) that used to use all of that same code is here, with the updates:

<?php
include('funcs.php');

$authenticate = &New LogIn;

$authenticate->username = $_POST['username'];
$authenticate->password = $_POST['password'];
$authenticate->referer = $_SERVER['HTTP_REFERER'];

$authenticate->siteLogin();
?>

<link rel="stylesheet" type="text/css" href="
<?php
$style = $_COOKIE['style'];
if(isset($style)){
  echo $style;
} else {
echo("css/style.css");
}
?>
" media="screen" />

now usually, as you can see, when the user gets logged in it says "you're now logged in, please wait while we transfer you," or some crap like that.  I just get a white screen on this, and I doublecheck my cookies as well to see if it worked or not and sure enough, no cookie from my login script.  just wondering if it's because i have some variables mixed up or if it simply isn't possible.  thanks in advance for any help.
fuck it or fight it

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 September 2006 - 01:43 AM

Variables within a class need to be referenced using $this->variable syntax. Eg;

if ((!$this->username) or (!$this->password)) {


#3 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 22 September 2006 - 01:45 AM

so in my case

$authenticate->variable?

or is the $this thing like universal...?
fuck it or fight it

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 September 2006 - 01:49 AM

No... You need to use $this. Maybe you should take a look at the manual for some class examples. Id'e also try and avoid putting any output within a class, its pretty bad practice.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users