php - Get id of logged in user to show categories -


i have table join handles user_id , cat_id , depending on user logged in depends on categories can see - however, can working explicitly typing in users id code , need know user logged in:

    <?php       try{         $results = $dbh->query("select *                                 cat_list                                 inner join user_cat_link_table                                 on cat_list.cat_id = user_cat_link_table.cat_id                                 user_cat_link_table.userid = 10 //here issue!                                 ");      }catch(exception $e) {         echo $e->getmessage();         die();     }      $docs = $results->fetchall(pdo::fetch_assoc);      foreach($docs $docs){        echo '         <a href="catview.php?cat_id='.$docs["cat_id"].'">             <div class="indexbox">                 <div class="indexboxheader">                     <i class="fa fa-users" style="font-size: 2em;"></i></div>                 <div class="indexboxfooter">                     <p>'.$docs["cat_title"].'</p>                 </div>             </div>         </a>         ';}     ?>  

the user gets signed in script:

<? session_start(); if(isset($_session['user'])){     header("location:home.php");     exit; }       $dbh=new pdo('mysql:dbname=######;host=localhost', '######', '######');/*change credentials connect database.*/     $email=$_post['username'];     $password=$_post['pass'];      if(isset($_post) && $email!='' && $password!=''){         $sql=$dbh->prepare("select * user_login username=?");         $sql->execute(array($email));      while($r=$sql->fetch()){         $p=$r['password'];         $p_salt=$r['psalt'];         $id=$r['id'];         $email=$r['username'];         $firstname=$r['firstname'];         $lastname=$r['lastname'];     }          $site_salt="subinsblogsalt"; /*common salt used password storing on site. can't change it. if want change it, change when register user.*/         $salted_hash = hash('sha256',$password.$site_salt.$p_salt);      if($p==$salted_hash){         $_session['user']=$id;         $_session['username']=$email;         $_session['firstname']=$firstname;         $_session['lastname']=$lastname;          header("location:home.php");      }else{         echo "<h2>username/password incorrect.</h2>";         }     } ?> 

there 3 tables, there user_login table, cat_list table , table handles relationship, burning issue getting script know user , how categories associated user rows in third table.

you using sessions in php page need use user id do:

<?php session_start(); $actusr = $_session['user'];     try{         $results = $dbh->query("select *                                 cat_list                                 inner join user_cat_link_table                                 on cat_list.cat_id = user_cat_link_table.cat_id                                 user_cat_link_table.userid = '$actusr'"); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -