Jump to content

Search the Community

Showing results for tags 'pdo session'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hey, I'm trying to echo out user info based on user $_SESSION['user_id'], but session is not set, it says "Undefined index: user_id". Login works, but user_id is not set. Class class User { public $uid = ""; public function userInfo($user_id) { global $db; $query = $db->prepare("SELECT `user_id`, `username`, `email` FROM `users` WHERE `user_id` = :id"); $query->bindValue(':id', $user_id); $query->execute(); return $query->fetch(); } public function login($login, $password){ global $db; $query = $db->prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :user AND `password` = :pass OR `email` = :user AND `password` = :pass"); $query->bindValue(':user', $login); $query->bindValue(':pass', $password); $query->execute(); $result = (bool) $query->fetchColumn(0); if($result) { $this->uid = $result['user_id']; } return $result; } } Login <?php if (isset($_POST['login'], $_POST['password'])) { $login = $_POST['login']; $password = sha1($_POST['password']); $errors = array(); if (empty($login) || empty($password)) { $errors[] = 'All fields required!'; } else { $user = new User; $log_in = $user->login($login, $password); if ($log_in) { $_SESSION['user_id'] = $user->uid; header('Location: account.php'); exit(); } else { $errors[] = 'Username/Email or password incorrect!'; } } if (!empty($errors)){ foreach ($errors as $error) { echo '<div id="error"><strong>', $error, '</strong></div><br />'; } } } ?> Account page $user_id = $_SESSION['user_id']; $user = new User; $data = $user->userInfo($user_id); echo $data['username'],'<br />'; echo $data['email'],'<br />'; echo '<pre>'; print_r($_SESSION['user_id']); echo '</pre>'; if(isset($_SESSION['user_id'])){ $user_id = $_SESSION['user_id']; $data = $user->userInfo($user_id); echo '<pre>'; print_r($data); echo '</pre>'; echo $data['username'],'<br />'; }else { echo 'bla'; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.