<?php class user { public $user; private $pass; public function checkuser() { $pdo = new pdo ('mysql:host=localhost;dbname=oop','root','mentormiszcz1e'); $row= $pdo-> query ("SELECT name,password FROM `trials` WHERE name= '".$_POST['user']."'"); while ($line= $row-> fetch()) { $this-> user= $line['name']; $this-> pass= $line['password']; $_SESSION['logged']= $_POST['user']; } else { } if ($line['name'] > 0) { } } // end while $row-> closeCursor(); } // end function } $user= new user; $user-> checkuser(); ?>
strona chroniona:
<?php include ("class.php"); } else { } ?>
Formularz:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us"> <head> </head> <body> <form action="class.php" method="post"> <div id="form"> <input type="text" name="user" /> <input type="password" name="pass" /> <input type="submit" value="Sign in" /> </div> </form> </body> </html>