View Full Version : session problem
xiaodao
12-12-2004, 09:28 AM
i always face this message, but soon after i refresh, can work again, why
Cannot redeclare check_valid_user() (previously declared in /home/book/include/global.php:3)
you are including a file more than once so it is declared more than once. maybe change include() to include_once() if you're not exactly sure where the problem lies.
xiaodao
12-12-2004, 11:57 AM
hmmm, even i use include_once seem did not solve the problem, what i do is
i create a function in global.php call
function check_valid_user() {
if(!session_is_registered(valid_user)) {
include 'login.php';
exit;
}
}
then i include it in other files
<?
include_once 'global.php';
check_valid_user();
?>
then come out the problem when i access the files directly
schotte
12-12-2004, 12:11 PM
Another reason for this error is, that you try to declare the function twice. ie you write function check_valid_user() {...} in the global.php and then write it again in a file like in the global.php. Thus having two functions with the same name, if you know what I mean.
Frank
marek_mar
12-12-2004, 12:33 PM
You can use the function function_exists() (http://www.php.net/function_exists).
xiaodao
12-12-2004, 01:30 PM
Another reason for this error is, that you try to declare the function twice. ie you write function check_valid_user() {...} in the global.php and then write it again in a file like in the global.php. Thus having two functions with the same name, if you know what I mean.
Frank
i double check the script, no such error, it become very strange now
xiaodao
12-12-2004, 01:49 PM
here is the error msg
Fatal error: Cannot redeclare check_user() (previously declared in /home/phpart/public_html/book/include/global.php:4) in /home/phpart/public_html/book/include/global.php on line 3
it says i previously declared in global.php,then i redeclare at global.php line 3 but my global.php is like
<?
session_start();
function check_user() {
if(!session_is_registered(valid_user)){
include 'login.php';
exit;
}
}
?>
schotte
12-12-2004, 03:19 PM
Try this:
<?
session_start();
if (!function_exists("check_user")) {
echo "Function doesn't exist.";
function check_user() {
if(!session_is_registered(valid_user)){
include 'login.php';
exit;
}
}
} else {
echo "Function exists.";
}
?>
and let us know what you see.
Frank
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.