简体   繁体   中英

Php - get current user id to store in a session?

I'm building a small form and I'm having trouble figuring out how to link user data to what is submitted to the database. For instance, I can process user data into my db but I need to link the data they submit to their user id. Out of 6 tables, I have an "author" and "article" table both with "id" field sets and would like to link each author to the articles they submit by getting their id once logged in and storing it in a session, but am unsure as how to actually select and store their id. Here is the portion of my controller where I'd like to add a session for user id:

<?php
include_once $_SERVER['DOCUMENT_ROOT'] .
        '/includes/magicquotes.inc.php';

require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/access.inc.php';

if (!userIsLoggedIn())
{
    include '../login.html.php';
    exit();
}
if (isset($_GET['add']))
{
    $pagetitle = 'New Article';
    $action = 'addform';
    $text = '';
    $authorid = '';
    $id = '';
    $button = 'Add article';

    include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
...........

Any thoughts?

EDIT-

Author table with stored id:

id  name    email           password
1   John    John@mail.com   d8a6582c02d188df9ad89a6affa412f7

In the login function, retrieve the author id from the db and store in a new session variable. http://www.php.net/manual/en/session.examples.basic.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM