I am building a website that receive POST variables from a Mikrotik router Hotspot page. I used for offline test XAMPP v3.2.2 with PHP 7.1. Everything work fine offline but when i put the website on an online Webserver provided by Cpanel with PHP 7.1 (ea-php71) i got an error with header instruction for redirection.
I got this error :
PHP Warning: Cannot modify header information - headers already sent by
The source code of the page who gave me error
<?php
session_start();
require_once dirname(__FILE__).'/includes/wf_DbOperations.php';
if(!isset($_SESSION['logincust']))
{
header('Location: index.php');
}
?>
<!DOCTYPE html>
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<title>...</title>
</head>
<body>
<?php
if(isset($_SESSION['oauth_providerG']))
{
$db = new DbOperations();
if(!$db->checkOAUTH($_SESSION['oauth_providerG'],$_SESSION['oauth_uid']))
{
if($db->addUserMAC($_SESSION['oauth_uid'],$_SESSION['mac']))
{
$db->addUserGoogle($_SESSION['oauth_providerG'],$_SESSION['oauth_uid'],$_SESSION['first_name'],$_SESSION['last_name'],$_SESSION['email'],$_SESSION['gender'],$_SESSION['locale'],$_SESSION['picture'],$_SESSION['link']);
header('Location: '.$_SESSION['srvLink'].'/glogin.html');
}
}
else
{
if($db->addUserMAC($_SESSION['oauth_uid'],$_SESSION['mac']))
{
header('Location: '.$_SESSION['srvLink'].'/glogin.html');
}
}
}
if(isset($_SESSION['oauth_providerF']))
{
$db = new DbOperations();
if(!$db->checkOAUTH($_SESSION['oauth_providerF'],$_SESSION['oauth_uid']))
{
if(isset($_SESSION['email']))
{
if($db->addUserMAC($_SESSION['oauth_uid'],$_SESSION['mac']))
{
$db->addUserFacebook($_SESSION['oauth_providerF'],$_SESSION['oauth_uid'],$_SESSION['first_name'],$_SESSION['last_name'],$_SESSION['email']);
header('Location: '.$_SESSION['srvLink'].'/glogin.html');
}
}
else
{
if($db->addUserMAC($_SESSION['oauth_uid'],$_SESSION['mac']))
{
$db->addUserFacebookNoMail($_SESSION['oauth_providerF'],$_SESSION['oauth_uid'],$_SESSION['first_name'],$_SESSION['last_name']);
header('Location: '.$_SESSION['srvLink'].'/glogin.html');
}
}
}
else{
if($db->addUserMAC($_SESSION['oauth_uid'],$_SESSION['mac']))
{
header('Location: '.$_SESSION['srvLink'].'/glogin.html');
}
}
}
?>
</body>
</html>
I have try redirection with JS script location.replace but it doesn't keep variable send by Mikrotik router.
Thanks for your help.