Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define ( 'HOST', 'localhost' );
- define ( 'USER', 'root' );
- define ( 'PASS', 'isoevumed2004' );
- define ( 'DB', 'oopregister' );
- /** @noinspection PhpUndefinedClassInspection */
- class DB
- {
- function __construct ()
- {
- /** @noinspection PhpParamsInspection */
- $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
- }
- }
- class User
- {
- public function __construct ()
- {
- /** @noinspection PhpUnusedLocalVariableInspection */
- $db = new DB;
- }
- public function register ($trn_date, $name, $username, $email, $pass)
- {
- $pass = md5 ( $pass );
- /** @noinspection PhpParamsInspection */
- $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
- $checkuser = mysqli_query ( $con, /** @lang text */
- "Select id from users where email='$email'" );
- $result = mysqli_num_rows ( $checkuser );
- if ( $result == 0 ) {
- $register = mysqli_query ( $con, /** @lang text */
- "Insert into users (trn_date, name, username, email, password) values ('$trn_date','$name','$username','$email','$pass')" ) or die( mysqli_error () );
- return $register;
- } else
- {
- return false;
- }
- }
- public function login ($email, $pass)
- {
- $pass = md5 ( $pass );
- /** @noinspection PhpParamsInspection */
- $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
- $check = mysqli_query ( $con, /** @lang text */
- "Select * from users where email='$email' and password='$pass'" );
- $data = mysqli_fetch_array ( $check );
- $result = mysqli_num_rows ( $check );
- if ( $result == 1 )
- {
- $_SESSION[ 'login' ] = true;
- $_SESSION[ 'id' ] = $data[ 'id' ];
- return true;
- } else
- {
- return false;
- }
- }
- public function fullname ($id)
- {
- /** @noinspection PhpParamsInspection */
- $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
- $result = mysqli_query ( $con, /** @lang text */
- "Select * from users where id='$id'" );
- $row = mysqli_fetch_array ( $result );
- echo $row[ 'name' ];
- }
- public function session ()
- {
- if ( isset( $_SESSION[ 'login' ] ) ) {
- return $_SESSION[ 'login' ];
- }
- }
- public function logout ()
- {
- $_SESSION[ 'login' ] = false;
- session_destroy ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement