Jump to content

CMS Tutorial help


alkalinesi

Recommended Posts

Hey everyone, I'm new here so go easy on me. OK, so I followed the Content Management System tutorial and everything was working fine. But I then was adding a file uploader system where the user can create folders and upload images and I ran into the problem of needing the user_id. So my question is how do I grab the session user id? From my understanding the tutorials don't touch that and I'm trying everything to start the user id session, not quite sure if I'm explaining that right. As of right now I'm in the m_auth file where the log in is being validated and it looks like $stmt = the database query, so I'm trying to extract the user_id out of that. And I have $_SESSION['user_id'] = $stmt; Can anyone offer me any help or guidance? Thank you so much.

Link to comment
Share on other sites

Personally, I would add a new get_userid() method to the m_auth.php file.

 

This method would check to see if a $_SESSION['userid'] variable is set using isset(). It it is (meaning this method has already been called) it would return that session variable. Otherwise, it would query the database and get the user id based on the current logged in username ($_SESSION['username'].

 

For an example query, see the load_block() method within the m_cms.php file -- that does roughly what you'd need to do, selecting one column (in this case you'd want to change it to the user id column, which I think is just "id", but you'll need to check) based on one value passed into the query (you'd need to change it to the username rather than using $id).

 

Then, at the end of the method, you would set the $_SESSION['userid'] based on what the database query returned, and return that value.

 

You can't use "$_SESSION['user_id'] = $stmt;" because $stmt is just a temporary variable, and it only exists within the validateLogin() method, and nowhere else.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...