0

I have a strange bug with my script, i just want redirect user if the URL finish by '/' to the same URL without any '/' at the end.

i get this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/xxx/httpdocs/series.php:1) in /home/httpd/vhosts/xxx/httpdocs/series.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/mxxx/httpdocs/series.php:1) in /home/httpd/vhosts/xxx/httpdocs/series.php on line 8

Code:

<?php
$urlLast = $_SERVER['REQUEST_URI'];
$urlLast = substr($urlLast, -1);
if (($urlLast == '/') && (!strstr($_SERVER['REQUEST_URI'], 'en-streaming')))
{
    $newURL = substr($_SERVER['REQUEST_URI'],0,-1).'-en-streaming';
    header("Status: 301 Moved Permanently", false, 301);
    header("Location: ".$newURL."");
}
Bastien Bast Weber
  • 453
  • 2
  • 5
  • 12

3 Answers3

3

You can fix it by using

ob_start(); on the top of your script.

rohitcopyright
  • 362
  • 1
  • 2
  • 9
  • 1
    Kindly follow this link http://stackoverflow.com/questions/8028957/headers-already-sent-by-php I hope, it definitely help you. – rohitcopyright Sep 04 '13 at 09:34
1

Is there Unicode BOM before <?php?

When you saved your file with encoding "UTF-8 with BOM(Byte Order Mark)", special character sequence(0xEF 0xBB 0xBF) would be automatically inserted in beginning of file.

Just try saving file with "UTF-8 WITHOUT BOM" (if exists) or try another editor.

AFAIK UTF-8 in notepad.exe is "WITH BOM".

0

Remove trailing spaces before <?php

Also, remove spaces after ?> (if any)

Also, add ob_start() at the beginning of the file.

This saves the output in buffer cache instead of printing on the browser.

Pupil
  • 23,834
  • 6
  • 44
  • 66