...

View Full Version : header and php version



Trki
01-21-2012, 02:52 PM
Hi ... i have this: header('Location: "'.$redirect.'" '); when i echo my $redirect it show good url ... but when i try it .. nothing happend. Any ideas ?

http://sk.php.net/manual/en/function.header.php

The syntax is good .. but it worked when i had lower php version.... today i updated to 5.3 ... and from now it doesnt work why?

_Aerospace_Eng_
01-21-2012, 03:36 PM
Do you have an exit(); after it?
Try this

header("Location: $redirect");
exit();
Also it needs to come before you have any output to the browser.

Trki
01-21-2012, 05:14 PM
Do you have an exit(); after it?
Try this

header("Location: $redirect");
exit();
Also it needs to come before you have any output to the browser.

hm... i have this in my file:




<?php

session_start();

require_once './includes/functions.php';

connect();

$id_comment=clean_get_include($_GET['id_comment']);
$id_clanku=clean_get_include($_GET['id_clanku']);

$mysql_delete='DELETE FROM blog_comments WHERE id='.$id_comment.'';
$mysql_query=mysql_query($mysql_delete);



echo $redirect="http://www.example.com/clanok/blog_obsah/id/".$id_clanku."";

header('Location: "'.$redirect.'" ');
exit();





?>





and if i echo $redirect the url is good
doesnt work :( i have no idea where could be a problem :(

tangoforce
01-21-2012, 05:28 PM
//You cannot do this.
echo $redirect="http://www.example.com/clanok/blog_obsah/id/".$id_clanku."";

header('Location: "'.$redirect.'" ');

(

You can't echo the url first. You can only use header() BEFORE any output not after it.

See the link in my signature about headers for more information.

Also remove those double quotes from inside the header() call.

Trki
01-21-2012, 07:09 PM
You can't echo the url first. You can only use header() BEFORE any output not after it.

See the link in my signature about headers for more information.

Also remove those double quotes from inside the header() call.

i am still reading your topics .but ...

this: still not working


<?php

session_start();

require_once './includes/functions.php';

connect();

$id_comment=clean_get_include($_GET['id_comment']);
$id_clanku=clean_get_include($_GET['id_clanku']);

$mysql_delete='DELETE FROM blog_comments WHERE id='.$id_comment.'';
$mysql_query=mysql_query($mysql_delete);



$redirect="http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku."";

header('Location: '.$redirect.' ');
exit();





?>


or... the header should be in the TOP? but it of course not working

_Aerospace_Eng_
01-21-2012, 07:18 PM
Try this

<?php

session_start();

require_once './includes/functions.php';

connect();

$id_comment=clean_get_include($_GET['id_comment']);
$id_clanku=clean_get_include($_GET['id_clanku']);

$mysql_delete="DELETE FROM blog_comments WHERE id=$id_comment";
$mysql_query=mysql_query($mysql_delete);



$redirect = "http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku;

header("Location: $redirect");
exit();
?>

Trki
01-21-2012, 07:44 PM
Try this

<?php

session_start();

require_once './includes/functions.php';

connect();

$id_comment=clean_get_include($_GET['id_comment']);
$id_clanku=clean_get_include($_GET['id_clanku']);

$mysql_delete="DELETE FROM blog_comments WHERE id=$id_comment";
$mysql_query=mysql_query($mysql_delete);



$redirect = "http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku;

header("Location: $redirect");
exit();
?>

no nothing aaaaaaaa ... but it was working in past... just when i updated version to 5.3 ... its supported?

_Aerospace_Eng_
01-21-2012, 07:49 PM
Yes it is supported. Can you post your updated code?

Trki
01-21-2012, 07:52 PM
<?php

session_start();

require_once './includes/functions.php';

connect();

$id_comment=clean_get_include($_GET['id_comment']);
$id_clanku=clean_get_include($_GET['id_clanku']);

$mysql_delete="DELETE FROM blog_comments WHERE id=$id_comment";
$mysql_query=mysql_query($mysql_delete);



$redirect = "http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku;

header("Location: $redirect");
exit();
?>

BluePanther
01-21-2012, 08:10 PM
Check for new entries in your error log, and maybe turn display_errors on.

coding_begins
01-21-2012, 08:29 PM
Try the following at the start and end of the script ans see...
ob_start();
ob_flush();

BluePanther
01-21-2012, 08:34 PM
To respond to your PM, you'll find your error log either in your public_html (www, web root) folder OR in another defined directory/place (or in the log directory in the php install itself, but this is unlikely if you're on shared hosting).

Display_errors can be turned on in the php.ini :)

_Aerospace_Eng_
01-21-2012, 08:34 PM
Add

ini_set('display_errors','On');
error_reporting(E_ALL);
Above session_start();
That should start displaying errors if any.

Trki
01-21-2012, 08:44 PM
Add

ini_set('display_errors','On');
error_reporting(E_ALL);
Above session_start();
That should start displaying errors if any.

i put just this into my file:


<?php

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

header('Location: http://www.wtf.com');
exit();
?>


and


Warning: Cannot modify header information - headers already sent by (output started at ...........functions.php:258) in blog_obsah_delete_comment.php on line 6

the blog obsah delete cooment.php file is where we are trying use header command and on line 258 in functions.php is just " ?> " of the php file

tangoforce
01-21-2012, 08:59 PM
So somewhere you have whitespace - As I've mentioned in my topic.

Anything that is in the file that is not inside <?php and ?> is output - including spaces, returns, tabs etc. This is called whitespace because its spaces that you can't see but they are still valid characters. A bit like the number zero, you can't see it but its a valid number.

Check for whitespace, I reckon you've got it somewhere. Also when PHP suggests its the last line number what its really saying is that it's elsewhere.

IF you really can't nail this then as I've suggested in my topic and as coding_begins has also said, use output buffering as a dirty hack.

felgall
01-21-2012, 09:04 PM
If the problem is line 258 in functions.php then it sounds like you have a blank line at the end of that script (assuming that is the length of the script).

If that is the case then remove the ?> from the end of the script as all having that at the end does is to introduce the possibility of outputting blanks to the browser. Getting rid of it means you have eliminated the end of the file as a possible place for accidentally including blanks and only need worry about byte order marks or blanks being added at the start.

Trki
01-21-2012, 09:28 PM
So somewhere you have whitespace - As I've mentioned in my topic.

Anything that is in the file that is not inside <?php and ?> is output - including spaces, returns, tabs etc. This is called whitespace because its spaces that you can't see but they are still valid characters. A bit like the number zero, you can't see it but its a valid number.

Check for whitespace, I reckon you've got it somewhere. Also when PHP suggests its the last line number what its really saying is that it's elsewhere.

IF you really can't nail this then as I've suggested in my topic and as coding_begins has also said, use output buffering as a dirty hack.

how it would looks like with the output buffering? can u write it?

Trki
01-21-2012, 09:34 PM
If the problem is line 258 in functions.php then it sounds like you have a blank line at the end of that script (assuming that is the length of the script).

If that is the case then remove the ?> from the end of the script as all having that at the end does is to introduce the possibility of outputting blanks to the browser. Getting rid of it means you have eliminated the end of the file as a possible place for accidentally including blanks and only need worry about byte order marks or blanks being added at the start.

nothing happened i would want to use the dirty trick what suggest tango but ... i am not sure if i write it good.

tangoforce
01-21-2012, 09:34 PM
how it would looks like with the output buffering? can u write it?

Erm, didn't I give an example in my topic? Just in case you ignored it, coding_begins has given you the two functions you need.



ob_start();
ob_flush();

ob_start() goes at the beginning of your code and ob_end_flush() or ob_flush() goes at the end.

What do I need to write? - Thats pretty simple and well demonstrated in my thread.

Trki
01-21-2012, 09:43 PM
Erm, didn't I give an example in my topic? Just in case you ignored it, coding_begins has given you the two functions you need.



ob_start() goes at the beginning of your code and ob_end_flush() or ob_flush() goes at the end.

What do I need to write? - Thats pretty simple and well demonstrated in my thread.

i didnt ignore it... i read it ... but it didnt help me... but ... now ... i just for fun tried to add the ob start and ob flush to INDEX.php... to start and end.. and now it works... hm... what i just did? i have theory about putt all the web buffering into one and then release it ... or something like that but ... ah

BUT THX EVERYBODY WHO ADDED COMMENT HERE FOR HELP I APPRECIATE IT :)

tangoforce
01-21-2012, 10:05 PM
hm... what i just did?

It's explained in my topic.

Output buffering stops the server sending any content to the browser. Instead it saves it in a 'buffer' so that you can still modify the headers etc. Once you're done, you 'flush' it to the browser and everything in the buffer is then sent.

Trki
01-21-2012, 10:13 PM
It's explained in my topic.

Output buffering stops the server sending any content to the browser. .

Yea i read it. :) ok then my theory was right. Ok thx again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum