Bug #1418: REQUIRE function is outputting a byte into stream.
| From: | rod at 23net dot net | Date: | Sun, 16 May 1999 11:41:19 +0000 |
| Subject: | Bug #1418: REQUIRE function is outputting a byte into stream. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-5668@lists.php.net to get a copy of this message | ||
From: rod@23net.net
Operating system: UNIX
PHP version: 3.0.7
PHP Bug Type: Misbehaving function
Bug description: REQUIRE function is outputting a byte into stream.
Compilation definitions: MYSQL_INCLUDE=-I/usr/local/mysql/include
MYSQL_LFLAGS=-Wl,-rpath,/usr/local/mysql/lib -L/usr/local/mysql/lib
MYSQL_LIBS=-lmysqlclient
APACHE_INCLUDE=-I../apache_1.3.6/src/include -I../apache_1.3.6/src/os/unix
APACHE_TARGET=../apache_1.3.6/src/modules/php3
Apache Version: Apache/1.3.6
Apache Release: 10306100
Apache API Version: 19990320
Hostname/port: 23net.net:80
User/Group: www(502)/502
Max Requests: per child: 100 keep alive: on max per connection: 100
Timeouts: connection: 300 keep-alive: 15
Server Root: /etc/httpd
Loaded modules: mod_php3, mod_frontpage, mod_setenvif, mod_auth, mod_access, mod_alias, mod_userdir,
mod_actions, mod_imap, mod_asis, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_status,
mod_negotiation, mod_mime, mod_log_config, mod_env, http_core
I use a script on each page to verify sessions. It verifies the length of time since last activity
and that the remote address has not changed. If either condition is not met the user must relogin.
The start of the script is:
<?
/*
header.inc
*/
header("Expires: Mon, 26 Jul 1998 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H;i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
Require ("includes/verifylogin.inc");
Require ("includes/dbfunctions.inc");
$db="xxxxx";
$linkid=OpenCnct();
SelectDB($linkid,$db);
VerifyUser($p,$db);
PRINT "<HTML><HEAD><TITLE>$pagename</TITLE></HEAD>";
The problem is that the "VerifyUser" function wouldn't execute a header contained
within the function. When I called the page thru Netscape it would inform me that the content
length was 1. (the byte was not a visible character. In an attempt to find out where the offending
byte was coming from I placed exit; in various locations in the script. An exit; at any point prior
to "Require ("includes/dbfunctions.inc")" resulted in "Document contains no
data." An exit; after that line gave me the 1 byte. I placed exits inside the required file
and always got "Document contains no data" including an exit before the closing
"?>" in the file. I changed the REQUIRE to INCLUDE and the script functioned
correctly. Somehow the REQUIRE function itself was adding the byte!
If you'd like to see more info on my configuration I have PHPINFO() set up at http://www.23net.net/test3.php3
I do not have access to the php3.ini file on my host.
This is a copy of the dbfunctions.inc file:
<?
/*
dbfunctions.inc
*/
function OpenDB($host="localhost",$name="xxx",$pw="xxx"){
$linkid=mysql_pconnect($host,$name,$pw);
return $linkid;
}
function SelectDB($linkid,$db="xxx"){
$result=mysql_select_db($db,$linkid);
}
function VerifyUser($p,$db){
$result=mysql_db_query($db,"Select lastaddr,lastused from users where uid=$p");
$numrows=mysql_num_rows($result);
}
list($lastaddr,$lastused)=mysql_fetch_row($result);
$remoteaddr=GETENV(REMOTE_ADDR);
IF ($remoteaddr!=$lastaddr){
$ref=getenv(SCRIPT_NAME);
header("Location: https://server9000.net/23net/signin.php3?err=4&ref=$ref");
exit;
}
$result=mysql_db_query($db,"Select NOW()+0");
$now=mysql_fetch_row($result);
IF ($now[0]>$lastused+1000){
$ref=getenv(SCRIPT_NAME);
header("Location: https://server9000.net/23net/signin.php3?err=4&ref=$ref");
exit;
}
$result=mysql_db_query($db,"update users set lastused=null where uid=$p");
}
function GetUserName($p,$db){
$result=mysql_db_query($db,"select uname from users where uid=$p");
$user=mysql_fetch_row($result);
return $user[0];
}
?>
Rod Kreisler
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net