-1

I am using a PHP for my development. but at the time of login I am getting error as PHP Warning: session_start(): Cannot send session cache limiter - headers already sent

This is my session file and added at top of the page.

My code - connection_config.php

<?php
session_start();
//ob_start();
//error_reporting(1);
$server ='localhost';          
$user ='**********';          
$password ='*********';              
$database = '**********';

define ('DB_HOST', $server);
define ('DB_USER', $user);
define ('DB_PASSWORD', $password);
define ('DB_NAME', $database);

function get_connection()
{ 
    $connection=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
    // Check connection
    if (mysqli_connect_errno())
    {
        echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
    }else
    {
        return $connection; 
    }
}
?>

In mysql_function.php

<?php
require_once("connectin_config.php");

In function.php

<?php
require('mysql_functions.php');

In index.php

<?php
include('function/function.php');

login.php

<?php
include('function/function.php');
$mess='';

if(isset($_POST['submit'])){

record_set('get_data','SELECT * FROM `admin` WHERE  `email`="'.$_POST['email'].'" and password="'.md5($_POST['password']).'"' );
    if($totalRows_get_data){
    $row_get_data= mysqli_fetch_assoc($get_data);
        $mess='login Successfully'; 
        $_SESSION['admin_id']=$row_get_data['id'];
        $_SESSION['admin_phone']=$row_get_data['phone'];
        $_SESSION['admin_fname']=$row_get_data['fname'];
        $_SESSION['admin_lname']=$row_get_data['lname'];
        $_SESSION['user_type']=$row_get_data['user_type'];
        $_SESSION['admin_image']=$row_get_data['image'];
        $_SESSION['admin_cdate']=$row_get_data['cdate'];
        reDirect('index.php'); 
    }else{



        $mess='Username or Password Invalid';
    }

}
?>

1 Answers1

0

I cant comment put all your php codes before <!DOCTYPE html> or in body tags!

Make sure you dont have spaces between <? php tags. where you include files.

Turn on error reporting :

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

Check error_log file in C:\wamp\logs\php_error.txt if you are using wampserver on localhost.

Try testing for isset($_SESSION) If it already exists then do not use session_start();

Look like you are passing second session start from another file try Like this :

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

Use session_start() before anything else.

  • Tried your solution. On page load, first line is coming as - Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/project/public_html/admin/login.php:1) – Ehane Kalvein Feb 24 '20 at 10:14
  • @EhaneKalvein Show us complete login.php please –  Feb 24 '20 at 10:19
  • login.php looks fine to me instead of using md5 hash, you should use php default hash type, can you add function.php is well ? thanks –  Feb 24 '20 at 10:25
  • My issue is resolved @Zelay Thanks for helping me – Ehane Kalvein Feb 24 '20 at 10:30