Results 1 to 10 of 17
Thread: Cannot Redeclare Function() (previously declared in......) in ....... on line 15
-
Cannot Redeclare Function() (previously declared in......) in ....... on line 15
13 Jan 2012 @ 11.22 Fatal error: Cannot redeclare loggedin() (previously declared in C:\xampp\htdocs\php\login\core.php:10) in C:\xampp\htdocs\php\login\core.php on line 15
This error always comes up! Please help!! This is my index page. I Already made a function in 'core.php' and the functions name is 'loggedin'.
PHP Code:<?phperror_reporting (E_ALL ^ E_NOTICE) ;require 'config.php' ;require 'core.php' ;echo '<h1>Index</h1>' ;
if (loggedin()) {$firstname = getuserfield ('firstname') ;$surname = getuserfield ('surname') ; echo '<u>Homepage</u><br><br>You are logged in as ' .$firstname.' '.$surname.'!<br><br><a href="profile.php">Go To Your Profile!</a><br><br><br><a href="logged_out.php">Logout</a>' ;} else {include 'loginform.php' ;}
?>
-
13 Jan 2012 @ 12.09 Apparently you have declared a function called "loggedin" twice. You can't have two functions with the same name (in the same namespace).
-
13 Jan 2012 @ 12.15 I didn't us it twice!
I made a file called 'core.php' where all the functions are there.
and I included the file (core.php) in the index page and used the function.
-
13 Jan 2012 @ 12.24 Double-check you're only including core.php once then. Perhaps include_once() or require_once() might solve the issue.
-
-
13 Jan 2012 @ 13.07 Rather than us trying to guess what the problem is, why don't you post the contents of core.php and also the php from your index file.
-
13 Jan 2012 @ 13.13 This is my core.php
PHP Code:<?php
ob_start();
session_start();
$current_file = $_SERVER['SCRIPT_NAME'];
function loggedin() {
if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
return true;
} else {
return false;
}
}
function getuserfield($field) {
$query = "SELECT `$field` FROM `users` WHERE `id`='".$_SESSION['user_id']."'";
if ($query_run = mysql_query($query)) {
if ($query_result = mysql_result($query_run, 0, $field)) {
return $query_result;
}
}
}
?>
-
13 Jan 2012 @ 13.21 This is my index.php
PHP Code:<?php
require 'core.php';
require 'config.php';
if (loggedin()) {
$firstname = getuserfield('firstname');
$surname = getuserfield('surname');
echo 'You are logged in, '.$firstname.' '.$surname.'!<br><br><a href="logout.php">Logout</a>';
} else {
include 'loginform.php';
}
?>
-
13 Jan 2012 @ 13.54 Is core.php being called in any of the other files or loggedin() being defined in any other file (config.php, logout.php, loginform.php)?
Is this all custom code or are you extending a framework or cms that might also have a similar function?
A quick google search suggested wrapping the following around your loggedin() function:
I can't think of anything else at this time - Janvt is the php guru around here, he might be able to suggest something else.PHP Code:if(!function_exists('loggedin')) {
}
-
13 Jan 2012 @ 13.57 Its used in 'loginform.php'.
Its all custom codes.
Thanks! I'll try that.



6Likes
LinkBack URL
About LinkBacks













Displaying Search Results
Agree with you.... Generally, we don't have control over display...