php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40615 session_start() kills link resource variable
Submitted: 2007-02-23 23:08 UTC Modified: 2007-02-23 23:39 UTC
From: jan dot morten dot sorensen at organizer dot net Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.1 OS: Win2K
Private report: No CVE-ID: None
 [2007-02-23 23:08 UTC] jan dot morten dot sorensen at organizer dot net
Description:
------------
I have version 5.1.2. THIS MIGHT HAVE BEEN FIXED IN 5.2.1!!!

First use mysql_connect() on an included file and return the resource identifier and store this in a variable.
Then call session_start()
Now you have lost your resource identifier!
Calling session_start() first fixes the problem.

Reproduce code:
---------------
file1.php
function connect_to_db() {
  $link = mysql_connect($host, $user, $pass) or die(err_msg);
  mysql_select_db($db) or die(err_msg);
  return $link;
}
file2.php
include 'file1.php';
$link = connect_to_db();
echo $link;
session_start();
echo $link;

Expected result:
----------------
link resource id# ?
link resource id# ?

replace ? with a number

Actual result:
--------------
link resource id# ?
0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-23 23:39 UTC] johannes@php.net
I guess you have register_globals enabled and a session variable overwriting your local variable. Except for that please report only bugs related to the latest version of PHP
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC