Jump to content

Fatal Error : Cannot redeclare function ( when functions are own page)


justin7410
Go to solution Solved by Jessica,

Recommended Posts

Hey there guys !

 

so i have finally finished my register log-in page , and with that i have created a couple functions pages , as i am sure you can assume all the functions for logic will be called from these pages.

 

now i have one called users , i.e for login , registration , check if active, etc..

 

and i have one for more general functions page called general , i.e for redirects, and input sanitation.

 

anyway my register login page works flawless ( well i guess more 90 % done 90 % left to go ).

 

and now when im on the index page or my main page essentially i now see a fatal error:

 


Fatal error: Cannot redeclare email() (previously declared in /home/justin/public_html/core/functions/general.php:2) in /home/justin/public_html/core/functions/general.php on line 4

 

now i see that it is telling me exactly where the error is , yet i dont understand as to why i am seeing this .

 

im not quite sure as to how the function is being declared already , when the function is only being called once or twice on the register page.

 

just to show you guys what im talking about

 

my code:

 

 

general.php ( FUNCTIONS ARE STORED)

function email($to, $subject, $body){mail($to, $subject, $body, 'From: support@j.m.com');
}
function email_to_activate($to, $subject, $body){
mail($to, $subject, $body, 'From: activate@j.m.com');
}
function email_user_for_recovery($to, $subject, $body){
mail($to, $subject, $body, 'From: recovery@j.m.com');
}


function logged_in_redirect(){
if (logged_in() === true ) 
header("Location: index.php");
} 


function protect_page() { // redirects if user is not logged in .. user gets no access page
if (logged_in() === false ) {
header('Location: no_permission.php');
exit();
}
}

function admin_access() {
global $user_data;
if (has_access($user_data['user_id'], 1) === false) {
header('Location: index.php');
exit();
}


}


function page_redirect() {   // if user not logged in redirect goes to index page
if (logged_in() === false ) {
header('Location: index.php');
exit();
}
}


function redirect(){  // redirects regardless of logged in or not
header('Location: index.php');
exit();
}


function array_sanitize(&$item){
$items = strip_tags(htmlentities(mysql_real_escape_string($item)));


}


function sanitize($data) {
return strip_tags(htmlentities(mysql_real_escape_string($data)));
}


function output_errors($errors){
$output = array();
foreach($errors as $error){
$output[] =  $error ;
}
return '<ul>' . implode($output) . '</ul>';
}

and index.php 

 

 

 

// CORE FUNCTIONS - DATABASE CONNECT - SESSIONS & COOKIES

include('include/init.php');

// HEADER INFO - META TAGS - LINKS - SCRIPTS

include('include/header.php');

// LOG USER IN
 if (logged_in() === true){
include ('include/widgets/loggedin.php');
 } else {
include('include/widgets/login.php');
 }



 // WEBSITE LOGO
include('include/logo_head.php');


// NAVIGATION BAR
include('include/navbar.php');


// MAIN PAGE

include('include/topbanner.php'); 
include('include/topbanner2.php'); 

                                    <----- Error shows up here and cuts off the rest of the page.
include('include/mainbody.php'); 



// FOOTER
include('include/footer.php');

as i  mention in the code above, the page spits about half the output then cuts off and displays that error message. This confuses me a bit more actually.

 

any suggestions as to why this is happening ? 

 

EDIT : to add init.php ( CORE FILE )

 

 

if(!isset($_SESSION))
{
session_start();
}


 error_reporting(E_ALL| E_STRICT);
 ini_set('display_errors', 1);


require ('core/database/dbconnect.php');
require ('core/functions/general.php');
require ('core/functions/users.php');
require 'core/queries/dbqueries.php';




$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);






if (logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'email', 'gender', 'country', 'month' ,'date' , 'year', 'pass_recover', 'type');
if (user_active($user_data['username']) === false){
session_destroy();
header('Location: index.php');
exit();
}
if($current_file !== 'change_password.php' && $current_file !== 'logout.php' && $user_data['pass_recover'] == 1 ){
header('Location: change_password.php?force');
exit();
}
}


$errors = array();
Edited by justin7410
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.