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+A pache2.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_global s 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,$DBUSE R,$DBPASS,$DBHO ST,$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><b r>Sorry this site is currently not available</center><br>".$c onn->getError();
exit();
}[/PHP] This worked when i turn off postgresql.
I can't do this:
[PHP]require("checku ser.inc.php");
if($USER_ISLOGI N) {
include("mainme nu.inc.php");
include("logini ndex.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_di r = 'kunjung/inc/';
//include ($lvc_include_d ir.'new-visitor.inc.php ');
$conn=new DBConnection ($DBNAME,$DBUSE R,$DBPASS,$DBHO ST,$DBPORT);
if(!$conn->init()) {
// Connection to the database is not established
echo "<center><br><b r>Sorry this site is currently not available</center><br>".$c onn->getError();
exit();
}
$res=new DBResult($conn) ;
$res->execSQL("selec t * from fg");
$HARINI_FG=arra y();
while($res->fetchNext()) {
$HARINI_FG[$res->row->id]=$res->row->name;
}
$res->free();
unset($res);
$TMP_TITLE="";
$TMP_NAVTOP=arr ay();
$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($GLO BALS["TMP_NAVTOP "],"<a class=link href='kunjung/index.php'>$str </a>");
}else{
array_push($GLO BALS["TMP_NAVTOP "],"<a class=link href=$PHP_SELF? stateid=$link>$ str</a>");}
}
function AddContent($str ) {
$GLOBALS["TMP_CONTEN T"].=$str;
}
function setTemplate($st r) {
$GLOBALS["TMP_TEMPLA TE"]=$str;
}
AddTitle("HARIN I RECRUITMENT CREW");
AddContent("<ta ble border=0 cellpadding=0 cellspacing=0 align=center width=80% ><tr><td valign=top>");
require("checku ser.inc.php");
if($USER_ISLOGI N) {
include("mainme nu.inc.php");
include("logini ndex.inc.php");
} else {
#AddContent("aw al- LOGIN");
# AddNavTop("Home ","home");
# AddNavTop("Abou t Us","aboutus" );
# AddNavTop("More Info","info");
# AddNavTop("Cont act Us","contact" );
# AddNavTop("Logi n","login");
# switch($stateid ) {
# case "login" :
AddContent(Thro wMessage("<div align=center>Ty pe in your username and password</center>"));
AddContent(Thro wBoxTop("LOGIN" ));
AddContent("<ta ble><form action=$PHP_SEL F?loginstate=lo gin&stateid=log in method=post><tr ><td>Username </td><td><input name=xusername size=15></td></tr>".
#AddContent("<t able><form action=$PHP_SEL F?loginstate=$l ogstate method=post><tr ><td>Username </td><td><input name=xusername size=15></td></tr>".
"<tr><td>Passwo rd</td><td><input type=password name=xpassword size=15></td></tr>".
"<tr><td colspan=2 align=center><i nput type=submit value=Login></td></tr>".
"<tr><td colspan=2 align=center>$m sgloginerror</td></tr>".
"</form>".
"</table>");
AddContent(Thro wBoxBottom());
# break;
/*
case "aboutus" :
AddContent(getF ileContent("$HA RINI_TEMPLATES/aboutus.html")) ;
break;
case "contact" :
AddContent(getF ileContent("$HA RINI_TEMPLATES/contactus.html" ));
break;
default :
AddContent(getF ileContent("$HA RINI_TEMPLATES/welcome.html")) ;
break;
}
*/
}
AddContent("</td></tr></table>");
setTemplate(get FileContent("$H ARINI_TEMPLATES/crew2.html"));
if(!$nothtml) {
$tdwidth=round( 720/(sizeof($TMP_NA VTOP)+1));
if($tdwidth>100 ) $tdwidth=100;
$TMP="<table border=0 cellpadding=0 cellspacing=10 align=center><t r>";
$bil=0;
foreach($TMP_NA VTOP as $key=>$val) {
#$TMP.="<td background=$HAR INI_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){$ga b .= "| ".$val." | ";}else{$ga b .= $val." | ";}
}
if($gab == " | ")$gab="";
$TMP.="</tr><tr><td colspan=$bil align=center>$g ab</td></tr></table>";
if($USER_ISLOGI N) {
$USERNAME="$USE R_USERNAME";
$REALUSERNAME=" $USER_NAME";
} else {
$USERNAME="Not login";
$REALUSERNAME="-";
}
$TMP_TEMPLATE=s tr_replace("##t itle",$TMP_TITL E,$TMP_TEMPLATE );
$TMP_TEMPLATE=s tr_replace("##u sername",$USERN AME,$TMP_TEMPLA TE);
$TMP_TEMPLATE=s tr_replace("##u serrealname",$R EALUSERNAME,$TM P_TEMPLATE);
$TMP_TEMPLATE=s tr_replace("##u rl-start",$HARINI_ URL,$TMP_TEMPLA TE);
$TMP_TEMPLATE=s tr_replace("##i plogin",$REMOTE _ADDR,$TMP_TEMP LATE);
$TMP_TEMPLATE=s tr_replace("##d ate",date("D, d M Y",time()),$TMP _TEMPLATE);
$TMP_TEMPLATE=s tr_replace("##t opmenu",$TMP,$T MP_TEMPLATE);
$TMP_TEMPLATE=s tr_replace("##c ontent",$TMP_CO NTENT,$TMP_TEMP LATE);
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.
I recently given a task to upgrade a running server (PostgreSQL7.3+ Apache2.0+PHP4. 2) to a new server with PostgreSQL8.1+A pache2.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_global s 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,$DBUSE R,$DBPASS,$DBHO ST,$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><b r>Sorry this site is currently not available</center><br>".$c onn->getError();
exit();
}[/PHP] This worked when i turn off postgresql.
I can't do this:
[PHP]require("checku ser.inc.php");
if($USER_ISLOGI N) {
include("mainme nu.inc.php");
include("logini ndex.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_di r = 'kunjung/inc/';
//include ($lvc_include_d ir.'new-visitor.inc.php ');
$conn=new DBConnection ($DBNAME,$DBUSE R,$DBPASS,$DBHO ST,$DBPORT);
if(!$conn->init()) {
// Connection to the database is not established
echo "<center><br><b r>Sorry this site is currently not available</center><br>".$c onn->getError();
exit();
}
$res=new DBResult($conn) ;
$res->execSQL("selec t * from fg");
$HARINI_FG=arra y();
while($res->fetchNext()) {
$HARINI_FG[$res->row->id]=$res->row->name;
}
$res->free();
unset($res);
$TMP_TITLE="";
$TMP_NAVTOP=arr ay();
$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($GLO BALS["TMP_NAVTOP "],"<a class=link href='kunjung/index.php'>$str </a>");
}else{
array_push($GLO BALS["TMP_NAVTOP "],"<a class=link href=$PHP_SELF? stateid=$link>$ str</a>");}
}
function AddContent($str ) {
$GLOBALS["TMP_CONTEN T"].=$str;
}
function setTemplate($st r) {
$GLOBALS["TMP_TEMPLA TE"]=$str;
}
AddTitle("HARIN I RECRUITMENT CREW");
AddContent("<ta ble border=0 cellpadding=0 cellspacing=0 align=center width=80% ><tr><td valign=top>");
require("checku ser.inc.php");
if($USER_ISLOGI N) {
include("mainme nu.inc.php");
include("logini ndex.inc.php");
} else {
#AddContent("aw al- LOGIN");
# AddNavTop("Home ","home");
# AddNavTop("Abou t Us","aboutus" );
# AddNavTop("More Info","info");
# AddNavTop("Cont act Us","contact" );
# AddNavTop("Logi n","login");
# switch($stateid ) {
# case "login" :
AddContent(Thro wMessage("<div align=center>Ty pe in your username and password</center>"));
AddContent(Thro wBoxTop("LOGIN" ));
AddContent("<ta ble><form action=$PHP_SEL F?loginstate=lo gin&stateid=log in method=post><tr ><td>Username </td><td><input name=xusername size=15></td></tr>".
#AddContent("<t able><form action=$PHP_SEL F?loginstate=$l ogstate method=post><tr ><td>Username </td><td><input name=xusername size=15></td></tr>".
"<tr><td>Passwo rd</td><td><input type=password name=xpassword size=15></td></tr>".
"<tr><td colspan=2 align=center><i nput type=submit value=Login></td></tr>".
"<tr><td colspan=2 align=center>$m sgloginerror</td></tr>".
"</form>".
"</table>");
AddContent(Thro wBoxBottom());
# break;
/*
case "aboutus" :
AddContent(getF ileContent("$HA RINI_TEMPLATES/aboutus.html")) ;
break;
case "contact" :
AddContent(getF ileContent("$HA RINI_TEMPLATES/contactus.html" ));
break;
default :
AddContent(getF ileContent("$HA RINI_TEMPLATES/welcome.html")) ;
break;
}
*/
}
AddContent("</td></tr></table>");
setTemplate(get FileContent("$H ARINI_TEMPLATES/crew2.html"));
if(!$nothtml) {
$tdwidth=round( 720/(sizeof($TMP_NA VTOP)+1));
if($tdwidth>100 ) $tdwidth=100;
$TMP="<table border=0 cellpadding=0 cellspacing=10 align=center><t r>";
$bil=0;
foreach($TMP_NA VTOP as $key=>$val) {
#$TMP.="<td background=$HAR INI_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){$ga b .= "| ".$val." | ";}else{$ga b .= $val." | ";}
}
if($gab == " | ")$gab="";
$TMP.="</tr><tr><td colspan=$bil align=center>$g ab</td></tr></table>";
if($USER_ISLOGI N) {
$USERNAME="$USE R_USERNAME";
$REALUSERNAME=" $USER_NAME";
} else {
$USERNAME="Not login";
$REALUSERNAME="-";
}
$TMP_TEMPLATE=s tr_replace("##t itle",$TMP_TITL E,$TMP_TEMPLATE );
$TMP_TEMPLATE=s tr_replace("##u sername",$USERN AME,$TMP_TEMPLA TE);
$TMP_TEMPLATE=s tr_replace("##u serrealname",$R EALUSERNAME,$TM P_TEMPLATE);
$TMP_TEMPLATE=s tr_replace("##u rl-start",$HARINI_ URL,$TMP_TEMPLA TE);
$TMP_TEMPLATE=s tr_replace("##i plogin",$REMOTE _ADDR,$TMP_TEMP LATE);
$TMP_TEMPLATE=s tr_replace("##d ate",date("D, d M Y",time()),$TMP _TEMPLATE);
$TMP_TEMPLATE=s tr_replace("##t opmenu",$TMP,$T MP_TEMPLATE);
$TMP_TEMPLATE=s tr_replace("##c ontent",$TMP_CO NTENT,$TMP_TEMP LATE);
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.
Comment