0

I know this has been asked a million times, but I've gone through all the answers to no avail, and as I only have a small amount of code, I figured it's a relatively simple fix (I hope). The frustrating thing is, is that php file works perfectly on one server, but not on another.

I'm receiving this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/thepcguy/public_html/ship_image/functions/function-redirect.php:1) in /home/thepcguy/public_html/ship_image/functions/function-redirect.php on line 9

relating to this file

<?php require_once('../Connections/ships.php');

if ($_GET['shore'] == "1") {
   header('Location: ../shore_establishment.php?ship_id=' .urlencode($_GET['ship_id']) . "&shore=1" . "&page=ship");
   //echo"first";
} else if ($_GET['shore'] == "0") {
  header('Location: ../shipinfo.php?ship_id=' .urlencode($_GET['ship_id']). "&shore=0" . "&page=ship");
   //echo"second";
};

?>

For interests sake, the file ships.php is:

<?php
$hostname_ships = "xxxxx";
$database_ships = "xxxxx";
$username_ships = "xxxxx";
$password_ships = "xxxxx";
$ships = mysql_pconnect($hostname_ships, $username_ships, $password_ships); 
?>
user2406993
  • 257
  • 3
  • 7
  • 21
  • I'll check that one out, but I have looked at several results. thanks – user2406993 Feb 25 '14 at 15:23
  • What's on line 9 of function-redirect.php? Are you absolutely certain you do not have any output (even whitespaces) in ships.php? – Brian Driscoll Feb 25 '14 at 15:25
  • There is probably a space at the beginning or end of one of your files, you will also want to end the current script with a `die` after you set your redirect. – cmorrissey Feb 25 '14 at 15:25
  • I'm as certain as I can be that there is no white space on either of the php files... in both cases I have moved the closing ?> to the end of the previous line, and the opening – user2406993 Feb 25 '14 at 15:31

3 Answers3

4

Most likely you get notification that mysql_* is deprecated, and that is actually outputted to your browser, therefore you can't send headers since output is already sent...

Probably one server doesn't send notification, and other do, that's why it works on one, and not on other. To test set this as first line in you file:

error_reporting(E_ALL ^ E_DEPRECATED);

Dexa
  • 1,641
  • 10
  • 25
0

You can try to use ob_start() at the top, and add ob_flush() at the end of the script. See if that helps.

dsoumgit
  • 63
  • 8
0

In a similar vein to Dexa's answer:

If $_GET['shore'] or $_GET['ship_id'] aren't set you will get a PHP notice. Which will start output.

Jim
  • 22,354
  • 6
  • 52
  • 80