Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // DEFINES
- define('DB_SERVER', 'localhost');
- define('DB_USERNAME', '');
- define('DB_PASSWORD', '');
- define('DB_DATABASE', '');
- // Core of Platform
- class Core{
- public $db;
- /*** for construction process ***/
- public function __construct(){
- $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
- if(mysqli_connect_errno()) {
- echo "Error: Could not connect to database.";
- exit;
- }
- }
- /*** for registration process ***/
- public function register($username,$password,$email){
- $password = md5($password);
- $sql="SELECT * FROM users WHERE username='$username' OR email='$email'";
- //checking if the username or email is available in db
- $check = $this->db->query($sql) ;
- $count_row = $check->num_rows;
- //if the username is not in db then insert to the table
- if ($count_row == 0){
- $sql1="INSERT INTO users SET username='$username', password='$password', email='$email'";
- $result = mysqli_query($this->db,$sql1) or die(mysqli_connect_errno()."Data cannot inserted");
- return $result;
- }
- else {
- return false;
- }
- }
- /*** for login process ***/
- public function login($username, $password){
- $password = md5($password);
- $sql2="SELECT user_id from users WHERE username='$username' and password='$password'";
- //checking if the username is available in the table
- $result = mysqli_query($this->db,$sql2);
- $user_data = mysqli_fetch_array($result);
- $count_row = $result->num_rows;
- if ($count_row == 1) {
- // this login var will use for the session thing
- $_SESSION['login'] = true;
- $_SESSION['uid'] = $user_data['user_id'];
- return true;
- }
- else{
- return false;
- }
- }
- /*** return user's data ***/
- public function get_user_data($user_id, $query){
- $result = mysqli_query($this->db,"SELECT * FROM users WHERE user_id = $user_id");
- $user_data = mysqli_fetch_array($result);
- echo $user_data[$query];
- }
- /*** starting the session ***/
- public function get_session(){
- return $_SESSION['login'];
- echo $_SESSION['login'];
- }
- /*** loging out ***/
- public function user_logout() {
- $_SESSION['login'] = FALSE;
- session_destroy();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement