SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Setting Sessions

    Hi,

    (assuming session_start() is allready started)
    I should be able to set sessions by doing this right
    PHP Code:
    $_SESSION['blahh'] = 'foobar'
    so in this case
    PHP Code:
    $_SESSION['email'] = $row['email']; 
    would set the
    PHP Code:
    $_SESSION['email'
    equal to what ever
    PHP Code:
    $row['email'
    was correct? So then i could just call on
    PHP Code:
    $_SESSION['email'
    for the email.

    Am i correct in this logic? I have never got sessions greatly.

  2. #2
    Non-Member
    Join Date
    Jun 2012
    Posts
    88
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You can test very quickly if it works or not by using echo to output the value in a variable.

    PHP Code:
    <?php
    session_start
    ();

    $row['email'] = 'foobar';

    $_SESSION['email'] = $row['email'];

    echo 
    $_SESSION['email'];

    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok, so my login script is not working.

    PHP Code:
             $row $lookup->fetchAll();
            if(
    $row[0] > 0){
                if(
    $row['salt1'].$rawPass.$row['salt2'] == $row['password'])
                {
                    
    $_SESSION['email'] = $row['email'];
                    
    $_SESSION['id'] = $row['id'];
                    
    $_SESSION['name'] = $row['name'];
                    
    $_SESSION['level'] = $row['level'];
                    
    $_SESSION['farmname'] = $row['farmname'];
                }
                
    $message .=  $row['name']."You have been logged in!";
                
    $title "Logged in!";
                } 
    This is the script that sets the sessions. I have also tryed echoing $row['name'] how ever nothing shows up. But when i print_r(row[0]) an array shows up correctly

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Cmarenburg View Post
    PHP Code:
    $row $lookup->fetchAll(); 
    FetchAll() brings back an array (PDO, right?) Judging by your code you only wanted one row, so change to fetch() otherwise, try accessing the first record in your array of results like this:
    PHP Code:
    $message .=  $row[0]['name']."You have been logged in!"


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
  •