Hello seniors,
How are you?
Well I need you help I am new student of php.
Now I am trying to make user login system so that user can login through their password and user name.
But I’m receiving this error.

“
Fatal error: Cannot redeclare loggedin() (previously declared in C:\xampp\htdocs\series\firstfile\DB\Logging the User In Part\core.inc.php:7) inC:\xampp\htdocs\series\firstfile\DB\Logging the User In Part\core.inc.php on line 12
”

Below is whole code:

This is index.php page containing code:

<?php
require 'core.inc.php';
require 'connect.inc.php';
if(loggedin()){
echo 'you are login.';
}else{
include 'loginform.inc.php';
}
?>

this is connect.inc.php containing code to connect with database

<?php
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';


$mysql_db = 'a_database';


if(!mysql_connect($mysql_host, $mysql_user, $mysql_pass) || ! mysql_select_db($mysql_db))     {
die(mysql_error());
}
?>

core.inc.php page, I think this is creating problem if this not the index.php

<?php
ob_start();
session_start();
$current_file = $_SERVER;


function loggedin(){
if(isset($_SESSION) && !empty($_SESSION)){
return true;
}else{
return false;
}
}
?>

last one page is loginform.inc.php which will check weather user have enter something or not after that check username and password is correct or not?

<?php
require 'core.inc.php';


if(isset($_POST) && isset($_POST)){
$username=$_POST;
$password=$_POST;
$password_hash = md5($password);


if(!empty($username) && ! empty($password)){
$query = "SELECT id FROM users WHERE username = '$username' AND password = '$password_hash'";
if($query_run = mysql_query($query)){
$query_num_rows = mysql_num_rows($query_run);
if($query_num_rows==0){
echo 'Invalid';
}else if($query_num_rows ==1){
$user_id = mysql_result($query_run, 0, 'id');
echo $user_id;
$_SESSION=$user_id;
header('Location: main.php');
}
}
}else{
echo 'You must enter a username and password.';
}
}
?>
<form action="<?php echo $current_file; ?>" method="POST">
Usrename: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Log in">
</form>

and db is containing these things

id  username    password                 firstname   surname
1   alex    32250170a0dca92d53ec9624f336ca24    Alex    Garrett

Now please help me out why is this script is returning error and how this problem will be solve.
Thanks

remove this line from loginform.inc, you have already included core.inc.php.

require 'core.inc.php';

or use

require_once('core.inc.php');

O thank you so much dear urtrivedi for my help.
this was my first experience to posted and share problem here.
but was a great experience
thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.