Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'not'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. I have followed the book closely and looked over the code to make sure it matches Larry's. However, no matter what I do, I am not able to load the session into the database when I run the sessions.php file as per the book. I was hoping on some help to figure out what the issue is. I am running PHP 5.4.10 and Mysql 5.5.29. Thanks for the help in advance! ******This is my db_sessions.inc.php file:********* <?php # Script 3.1 - db_sessions.inc.php /* * This page creates the functional interface for * storing session data in a database. * This page also starts the session. */ // Global variable used for the database // connections in all session functions: $sdbc = NULL; //diff than DBC bc this is meant for sessions... make global for session connections (does not have to be and in fact would only use one in general so change code accordingly) function open_session() { global $sdbc; $sdbc = mysqli_connect( 'localhost', 'root', 'pass', 'advPHP' ) ; return true; //always return somethign except for read function (indicate success Boolean rather than just true) } function close_session() { global $sdbc; return mysqli_close( $sdbc ); } function read_session( $sid ) { global $sdbc; $q = sprintf( 'SELECT data FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc, $sid) ); $r = mysqli_query( $sdbc, $q ); if( mysqli_num_rows($r) == 1) { list($data) = mysqli_fetch_array($r, MYSQLI_NUM); return $data; } else { return ''; } } function write_session($sid, $data) { global $sdbc; $q = sprintf( 'REPLACE INTO sessions (id, data) VALUES("%s", %s")', mysqli_real_escape_string($sdbc, $sid), mysqli_real_escape_string($sdbc, $data) ); $r = mysqli_query($sdbc, $q); return true; } function delete_session( $sid ) { global $sdbc; $q = sprintf( 'DELETE FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc, $sid) ); $r = mysqli_query( $sdbc, $q ); $_SESSION = []; // return mysqli_affected_rows($sdbc) ; return true; } function clean_session($expire) { global $sdbc; $q = sprintf('DELETE FROM sessions WHERE DATE_ADD (last_accessed, INTERVAL %d SECOND) < NOW()', (int) $expire); $r = mysqli_query($sdbc, $q); return true; } session_set_save_handler( 'open_session', 'close_session', 'read_session', 'write_session', 'delete_session', 'clean_session' ); session_start(); ******And this is my sessions.php file******** <?php # Script 3.2 - sessions.php /* This page does some silly things with sessions. * It includes the db_sessions.inc.php script * so that the session data will be stored in a database. */ // Include the sessions file: // The file already starts the session. require('db_sessions.inc.php'); ?><!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>DB Session Test</title> <link rel="stylesheet" href="style.css"> </head> <body> <?php print_r($_SESSION); // Store some dummy data in the session, if no data is present: if( empty($_SESSION) ) { $_SESSION['blah'] = 'umlaut'; $_SESSION['this'] = 3615684.45; $_SESSION['that'] = 'blue'; echo '<p> Session data stored. </p>'; } else { echo '<p>Curren session contains <pre>' . print_r($_SESSION, 1) . '</pre> </p>'; } if( isset($_GET['logout']) ) { session_destroy(); echo '<p>Session destroyed.</p>'; } else { echo '<a href="sessions.php?logout=true"> Log Out </a>'; } echo '<p> Session data: <pre>' . print_r($_SESSION, 1) . '</pre></p>'; echo '</body> </html>'; session_write_close(); ?>
×
×
  • Create New...