Jump to content

Header Location don't work on the server


brel
 Share

Recommended Posts

Hello every body i'm a beginner in php programming, i wroth for a php code it's works into my local seveur but don't works on line i need help please:

<?php

if(!empty($_POST['po']))

{?>

 

<?php

$message=mysql_real_escape_string(htmlentities($_POST['message']));

$id=($_POST['id']);

$chemin1=uploaderhistorique1('img1');

$chemin2=uploaderhistorique2('img2');

$chemin3=uploaderhistorique3('img3');

if($chemin1 !="erreur" AND $chemin2 !="erreur" AND $chemin3 !="erreur"){

$resultat=uphistorique($message, $chemin1, $chemin2, $chemin3, $id);

header("location:listerhistorique.php?mesg=<h2 style='color:white;'>Modification effectif</h2>");

exit();

}else{header("location:uphistorique.php?id=$id&mesg=<h2 style='color:red;'>Modification non effectif</h2>");

exit();

?>

<?php }}?>

Edited by brel
Link to comment
Share on other sites

There are two things about location headers.

 

1. For all headers in general, they must be sent before any content is displayed. This portion of code is display a few line breaks, so the header won't work:

{?><?php

2. The location header should have an absolute URL including "http:" and the full domain name

Link to comment
Share on other sites

i have all readdy done it with an absolut url with a full domaine name but it doesn't work in this case, that works in some without the url can i have an example please

 

this is my first methode :

 

<?php

if(!empty($_POST['po']))

{?>

 

<?php

$message=mysql_real_escape_string(htmlentities($_POST['message']));

$id=($_POST['id']);

$chemin1=uploaderhistorique1('img1');

$chemin2=uploaderhistorique2('img2');

$chemin3=uploaderhistorique3('img3');

if($chemin1 !="erreur" AND $chemin2 !="erreur" AND $chemin3 !="erreur"){

$resultat=uphistorique($message, $chemin1, $chemin2, $chemin3, $id);

header("location:http://mydomainename.com/contentfolder/listerhistorique.php?mesg=<h2 style='color:white;'>Modification effectif</h2>");

exit();

}else{header("location:http://mydomainename.com/contentfolder/uphistorique.php?id=$id&mesg=<h2 style='color:red;'>Modification non effectif</h2>");

exit();

?>

<?php }}?>

Edited by brel
Link to comment
Share on other sites

Like I mentioned earlier, you have line breaks being sent from the server.

 

You don't really need to separate your code into multiple PHP blocks, put it all within the same <?php ?> block and make sure there are no spaces or line breaks preceding it.

Link to comment
Share on other sites

i change my code but it doesnt works any more:

 

<?php

if(!empty($_POST['po'])){
$message=mysql_real_escape_string(htmlentities($_POST['message']));
$id=($_POST['id']);
$chemin1=uploaderhistorique1('img1');
$chemin2=uploaderhistorique2('img2');
$chemin3=uploaderhistorique3('img3');
if($chemin1 !="erreur" AND $chemin2 !="erreur" AND $chemin3 !="erreur"){
$resultat=uphistorique($message, $chemin1, $chemin2, $chemin3, $id);
header("location:http://mydomainename.com/contentfolder/listerhistorique.php?mesg=<h2 style='color:white;'>Modification effectif</h2>");
exit();
}else{header("location:http://mydomainename.com/contentfolder/uphistorique.php?id=$id&mesg=<h2 style='color:red;'>Modification non effectif</h2>");
exit();}
?>
Link to comment
Share on other sites

i post it like this in my page:

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include ("../db_conx6/db_conx6.php");
include ("root/php/include/fonc.php");
include ("adminses.php.inc");
if(!empty($_POST['po'])){
$message=mysql_real_escape_string(htmlentities($_POST['message']));
$id=($_POST['id']);
$chemin1=uploaderhistorique1('img1');
$chemin2=uploaderhistorique2('img2');
$chemin3=uploaderhistorique3('img3');
if($chemin1 !="erreur" AND $chemin2 !="erreur" AND $chemin3 !="erreur"){
$resultat=uphistorique($message, $chemin1, $chemin2, $chemin3, $id);
header("location:http://******/******/listerhistorique.php?mesg=<h2 style='color:white;'>Modification effectif</h2>");
}else{header("location:http://******/****/uphistorique.php?id=$id&mesg=<h2 style='color:red;'>Modification non effectif</h2>");}
}
?>
but nothing display, i juste got a white page nothing more,
but into my error_log file on the server 'ive got this : [06-Aug-2015 11:00:27 Europe/Berlin] PHP Parse error: syntax error, unexpected '}' in /home/-----/public_html/-----/valhistorique.php on line 16,
please somebody can tell me what should i do because i try to correct it but nothing change,
Thanks
Edited by brel
Link to comment
Share on other sites

It looks like you have an extra closing brace at the end of your code that shouldn't be there. If your code were indented properly it would be easy to catch that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...