header(Location ) and mysql probelm
Hello All,
My setup is PHP 4.3.3, mysql 3.32 running under RH 9 (2.4.20-8smp).
I have a login script (login.php) that once login credentials have been verified the script sets a few session variables and then redirects the browser to a second page. This second page has a script that queries a mysql database. The problem is this:
If in login.php is have
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/second_page.php");
then in second_page.php I get
mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
If I simply reload second_page.php the mysql_query runs as expected
However, if in login.php is have
header ("Refresh: 0; URL=http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/second_page.php");
then in second_page.php the mysql_query runs as expected the first time through.
The reason I want to use Location instead of Refresh is because Refresh is not part of the official HTTP specification and causes probelms with some browsers such as Safari.
CODE DETAILS
/* login.php */
ob_start(); // Start output buffering
ini_set("session.cookie_lifetime", 3600); // set the session cookie to 1 hour
session_start(); // Initialize a session
[SNIP]
session_write_close(); // Make sure session variables are written to disk
ob_end_clean(); // Delete the buffer
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/second_page.php");
exit;
/* second_page.php */
ob_start(); // Start output buffering
ini_set("session.cookie_lifetime", 3600); // set the session cookie to 1 hour
session_start(); // Initialize a session
[SNIP]
$DBC = mysql_connect("$DBHost", "$DBUser", "$DBPasswd");
/*
Dies the first time through with header("Location ... ") but works after page reoad.
Works first time through with header ("Refresh: 0; ..)
*/
if($DBC) {
$DBD = mysql_select_db($DataBase);
[SNIP]
}
Any ideas? I've been at this for a couple of days ...
Thanks,
Don