php - session_start() not working and giving warning although it's on the top of the page -


this code working in xampp it's not working after uploaded on server

<?php  ob_start(); session_start(); if(session_status()!=php_session_active) { session_start();} if(!isset($_session['username']) || !isset($_session['password'])) {     header('location:login.php'); } $connection=mysqli_query('localhost','username','password','dbname') ?> <!doctype html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 

the page has loaded fine it's giving error on top of page , because it's admin page must not open unless session set. warning getting right now.

warning: session_start(): cannot send session cache limiter - headers sent (output started @ /home3/index.php:1) in /home3/index.php on line 3  warning: cannot modify header information - headers sent (output started @ /home3/index.php:1) in /home3/index.php on line 7 

use below code , make sure not have space left on in code before <?php tag starts.

<?php  session_start(); ob_start(); 

note session can started before output starts on page , same rule applies header function in php.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -