SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with SESSIONS

    I have the following code where i've already initialized the $_SESSION['member_ID] variable, but i want i want to know is how can i use that variable outside of the below php code... so i can query the database using the $_SESSION['member_ID'] further down in the html code... (see inside wrapper tag)

    <?php
    session_start();

    if(!session_is_registered('member_ID')) :
    header('Location: index.php?msg=requires_login');
    endif;
    include 'db.php';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <div id="wrapper">
    <?php
    // HERE IS WHERE I WANT TO USE $_SESSION['member_ID']
    $_SESSION['member_ID'];
    ?>

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Session variables are similar to regular variables. For example, you can use this code:
    Code:
    $memberId = $_SESSION['member_ID'];
    and value from the member_ID will be saved to the $memberId variable.
    Then you can use this variable to create a database query.
    These sections of the PHP manual may be useful:
    http://php.net/manual/en/book.mysql.php
    http://php.net/manual/en/book.mysqli.php
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    session_start();

    $query "SELECT login FROM users WHERE id = '%d' ";

    $sql mysql_querysprintf$query$_SESSION['member_ID']) ) or die( mysql_error() );

    $row mysql_fetch_array$sql );

    echo 
    $row['login']; 
    my mobile portal
    ghiris.ro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •