WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0
Categories : PHP, Sessions, Databases, MySQL Click here to Update Your Picture
Dan Parry
Date : Feb 25th 2006
Grade : 3 of 5 (graded 2 times)
Viewed : 7498
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Dan Parry
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Having read an article on custom sessions stored in a database, I decided to rewrite the class and build it into a site framework I was working on. All went well until I started using a header() redirect on the login form, When the redirect completed I frequently received this message:

Duplicate entry '**ID_REMOVED**' for key 1
Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0

This also started appearing if a page was refreshed quickly. Thinking it was a configuration problem I started researching and contacted my hosting company

The class function for writing the session looked like this

<?
/* Write new data to database */
   
function _write($ses_id, $data) {
       
$session_sql = "UPDATE " . $this->ses_table
                     
. " SET ses_time='" . time()
                     .
"', ses_value='$data' WHERE ses_id='$ses_id'";
       
$session_res = @mysql_query ($session_sql, $this->dblink) or die (mysql_error());
        if (!
$session_res) {
            return
FALSE;
        }
        if (
mysql_affected_rows ()) {
            return
TRUE;
        }

       
$session_sql = "INSERT INTO " . $this->ses_table
                     
. " (ses_id, ses_time, ses_start, ses_value)"
                     
. " VALUES ('$ses_id', '" . time()
                     .
"', '" . time() . "', '$data')";
       
$session_res = @mysql_query ($session_sql, $this->dblink) or die (mysql_error());
        if (!
$session_res) {     
            return
FALSE;
        }         else {
            return
TRUE;
        }
    }

?>


The problem turned out to be within this function itself rather than the configuration

The problem stemmed from the way the return from UPDATE is handled and the scripts reliance on the mysql_affected_rows() command

If the UPDATE command is executed on a record and no values are altered the command exits with a value of 0 meaning that the result of mysql_affected_rows() is false

This occurs on redirects and fast refreshes because the time value hasn't changed so no values are altered in the row, mysql_affected_rows() is false and the function continues as no condition is met to return a value... the following INSERT then causes the problem

The solution was do execute a simple SELECT to get the number of rows for the session ID and if mysql_affected_rows() evaluated to false but the number of records is 1 return true

I hope this helps someone as it took me a while to figure this out



A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Simple PHP Form Auto Generation based on MySQL query
Categories : PHP, Form Processing, Databases, MySQL, Sessions
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
GroupIT Engine v1.00rc1
Categories : PHP, Content Management, MySQL, Databases
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
Email a user with out exposing email address
Categories : PHP, Databases, MySQL, Email
Invision Forums Latest Threads list
Categories : PHP, Miscellaneous, Databases, MySQL
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
How to thread a list of messages in database and show it in a treelike structure
Categories : PHP, MySQL, Databases
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
Browse a MySQL database & draw a tree view & load final items into a template page.
Categories : MySQL, Complete Programs, Algorithms, PHP, Databases