Hi all,
I recently given a task to upgrade a running server (PostgreSQL7.3+Apache2.0+PHP4.2) to a new server with PostgreSQL8.1+Apache2.2+PHP5.1 installed (all Fedora Core 6 packages). All is running well, except the old php scripts. Plz bare with me I'm not a programmer, I've spent a month researching the PHP manual, the net, other forum and still can't exactly point out the porblem.
I have set register_globals on and allow_call_time_pass_reference to true for backward compatibilty in order for these old php scripts to work in PHP5. The problem is I get immediate disconnection (session ended) after a succesfull db connection in the index.php script.
Things I know that works in index.php are:
[PHP]<?
require("/home/*/lib/config.inc.php");
$conn=new DBConnection ($DBNAME,$DBUSER,$DBPASS,$DBHOST,$DBPORT);
[/PHP] This worked becaused it was logged in my postgresql logger as follow:
LOG: connection received: host=[local]
LOG: connection authorized: user=xxxx database=xxxx
LOG: disconnection: session time: 0:00:00.01 user=xxxx database=xxxx host=[local]
[PHP]if(!$conn->init()){
//Connection to the database is not established
echo "<center><br><br>Sorry this site is currently not available</center><br>".$conn->getError();
exit();
}[/PHP] This worked when i turn off postgresql.
I can't do this:
[PHP]require("checkuser.inc.php");
if($USER_ISLOGIN) {
include("mainmenu.inc.php");
include("loginindex.inc.php");
} else {[/PHP] Before it can check table users in the database the connection was ended or there was no connection established.
Here is the complete code off index.php, I hope somebody out there can point out the problem.
[PHP]<?php
require("/home/*/lib/config.inc.php");
//$lvc_include_dir = 'kunjung/inc/';
//include ($lvc_include_dir.'new-visitor.inc.php');
$conn=new DBConnection ($DBNAME,$DBUSER,$DBPASS,$DBHOST,$DBPORT);
if(!$conn->init()) {
// Connection to the database is not established
echo "<center><br><br>Sorry this site is currently not available</center><br>".$conn->getError();
exit();
}
$res=new DBResult($conn);
$res->execSQL("select * from fg");
$HARINI_FG=array();
while($res->fetchNext()) {
$HARINI_FG[$res->row->id]=$res->row->name;
}
$res->free();
unset($res);
$TMP_TITLE="";
$TMP_NAVTOP=array();
$TMP_CONTENT="";
$TMP_TEMPLATE="";
$TMP_USERNAME="";
function AddTitle($str) {
$GLOBALS["TMP_TITLE"].=$str;
}
function AddNavTop($str,$link="stateid") {
global $PHP_SELF;
if ($link=="stat"){
array_push($GLOBALS["TMP_NAVTOP"],"<a class=link href='kunjung/index.php'>$str</a>");
}else{
array_push($GLOBALS["TMP_NAVTOP"],"<a class=link href=$PHP_SELF?stateid=$link>$str</a>");}
}
function AddContent($str) {
$GLOBALS["TMP_CONTENT"].=$str;
}
function setTemplate($str) {
$GLOBALS["TMP_TEMPLATE"]=$str;
}
AddTitle("HARINI RECRUITMENT CREW");
AddContent("<table border=0 cellpadding=0 cellspacing=0 align=center width=80% ><tr><td valign=top>");
require("checkuser.inc.php");
if($USER_ISLOGIN) {
include("mainmenu.inc.php");
include("loginindex.inc.php");
} else {
#AddContent("awal- LOGIN");
# AddNavTop("Home","home");
# AddNavTop("About Us","aboutus");
# AddNavTop("More Info","info");
# AddNavTop("Contact Us","contact");
# AddNavTop("Login","login");
# switch($stateid) {
# case "login" :
AddContent(ThrowMessage("<div align=center>Type in your username and password</center>"));
AddContent(ThrowBoxTop("LOGIN"));
AddContent("<table><form action=$PHP_SELF?loginstate=login&stateid=login method=post><tr><td>Username</td><td><input name=xusername size=15></td></tr>".
#AddContent("<table><form action=$PHP_SELF?loginstate=$logstate method=post><tr><td>Username</td><td><input name=xusername size=15></td></tr>".
"<tr><td>Password</td><td><input type=password name=xpassword size=15></td></tr>".
"<tr><td colspan=2 align=center><input type=submit value=Login></td></tr>".
"<tr><td colspan=2 align=center>$msgloginerror</td></tr>".
"</form>".
"</table>");
AddContent(ThrowBoxBottom());
# break;
/*
case "aboutus" :
AddContent(getFileContent("$HARINI_TEMPLATES/aboutus.html"));
break;
case "contact" :
AddContent(getFileContent("$HARINI_TEMPLATES/contactus.html"));
break;
default :
AddContent(getFileContent("$HARINI_TEMPLATES/welcome.html"));
break;
}
*/
}
AddContent("</td></tr></table>");
setTemplate(getFileContent("$HARINI_TEMPLATES/crew2.html"));
if(!$nothtml) {
$tdwidth=round(720/(sizeof($TMP_NAVTOP)+1));
if($tdwidth>100) $tdwidth=100;
$TMP="<table border=0 cellpadding=0 cellspacing=10 align=center><tr>";
$bil=0;
foreach($TMP_NAVTOP as $key=>$val) {
#$TMP.="<td background=$HARINI_URL/images/bgblue.gif width=$tdwidth align=center valign=middle >$val</td>\n";
#$TMP.="<td width=$tdwidth align=center valign=middle>$val</font></td>\n";
$bil += 1;
if($bil==1){$gab .= "| ".$val." | ";}else{$gab .= $val." | ";}
}
if($gab == " | ")$gab="";
$TMP.="</tr><tr><td colspan=$bil align=center>$gab</td></tr></table>";
if($USER_ISLOGIN) {
$USERNAME="$USER_USERNAME";
$REALUSERNAME="$USER_NAME";
} else {
$USERNAME="Not login";
$REALUSERNAME="-";
}
$TMP_TEMPLATE=str_replace("##title",$TMP_TITLE,$TM P_TEMPLATE);
$TMP_TEMPLATE=str_replace("##username",$USERNAME,$ TMP_TEMPLATE);
$TMP_TEMPLATE=str_replace("##userrealname",$REALUS ERNAME,$TMP_TEMPLATE);
$TMP_TEMPLATE=str_replace("##url-start",$HARINI_URL,$TMP_TEMPLATE);
$TMP_TEMPLATE=str_replace("##iplogin",$REMOTE_ADDR ,$TMP_TEMPLATE);
$TMP_TEMPLATE=str_replace("##date",date("D, d M Y",time()),$TMP_TEMPLATE);
$TMP_TEMPLATE=str_replace("##topmenu",$TMP,$TMP_TE MPLATE);
$TMP_TEMPLATE=str_replace("##content",$TMP_CONTENT ,$TMP_TEMPLATE);
echo $TMP_TEMPLATE;
flush();
}
$conn->close();
#echo "<HEAD> <LINK REL=\"SHORTCUT ICON\" HREF= \"/images\/favicon.ico\"> </HEAD>";
?>[/PHP]
Any help would be much appreciated. Thx all.