I have been figuring this out for years. I have a website with 500 users per day logging in, and often when they submit a news article, oddly for few users $_SESSION['user'] is lost and becomes null.
What is causing this? I thought this is a browser problem initially but i checked it works fine to me..
With the lost session variable the database INSERT also fails..
I use smarty, php 5 and apache on a dedicated server. Here is a part of code i am reproducing...
When the $_SESSION['user'] is null, mysql_insert_id() also becomes NULL.
<?php
session_start();
if(!isset($_SESSION['user']))
{
header("Location: /login.php");
}
mysql_query("INSERT into press_releases
(`date`,`category`,`title`,`desc`,`body`,`company`,`address`,`tel`,`url`,`keywords`
,`email`,`contribution`,`sponsored`,`user_ip`)
VALUES
('$date','$data[category]','$data[title]','$data[desc]','$data[content]','$data[company]', '$data[address]','$data[tel]','$data[url]'
,'$data[keywords]','$_SESSION[user]','$contribution','$sponsored','$user_ip')
",$link) or die("Insertion Failed:" . mysql_error());
// echo "<h3>Thank You</h3> We received your submission.";
$id = mysql_insert_id($link);
// IMPORTANT: Place front slash here when uploaded to server
?>