Je viens de tester un de mes sites sur un hébergement mutualité en PHP 4, et j'ai visiblement un truc qui cloche quand j'essaye de me connecter au back office :
Warning: Cannot send session cookie - headers already sent by (output started at /web/Xk/Xr/Xy/.../public/www/.../index.php:33) in /web/Xk/Xr/Xy/.../public/www/.../connexion.php on line 13
Les ... correspondent à des adresses.
Donc dans l'ordre j'initialise la variable de session que j'essaye de passer :
if (!isset($_SESSION['identifiant'])) {
$_SESSION['identifiant']= '';
}
Ensuite le code correspondant à la page de connexion :<?php
if (isset($_POST['identifiant'])) {
if ($_POST['identifiant'] != $identifiant) { // SI IDENTIFIANT INCORRECT
echo '<script langage="text/javascript">document.location.href="index.php?page=connexion&alerte='.$mess_identifiant.'"</script>';
exit();
}
if ($_POST['identifiant'] == $identifiant) { // SI IDENTIFIANT OK
if ($_POST['passe'] != $passe) { // Si pass incorrect
echo '<script langage="text/javascript">document.location.href="index.php?page=connexion&alerte='.$mess_motpasse.'"</script>';
exit();
}
else {
session_start(); // Sinon debut session
$_SESSION['identifiant']= $_POST['identifiant'];
echo '<script langage="text/javascript">document.location.href="administration.php"</script>';
}
}
}
?>
<h1>Connexion</h1>
<?php echo $alerte ?>
<form method="post" action="index.php?page=connexion">
<p><label>Identifiant : </label><input type="text" name="identifiant" /></p>
<p><label>Mot de passe : </label><input type="password" name="passe" /></p>
<p><input type="submit" value="OK"</p>
</form>
VoilàSinon sous un autre hébergeur mutu en PHP5 ça marche. je pense que j'ai fait une grosse boulette quelque part ?