Forum Moderators: coopster
I created a nice script that checks if the page has a .php extension to it and then redirects it to that same page, only WITHOUT the .php extension. So the problem is, the script doesn't work because it says "Headers have already been sent".
The only way to fix this is by placing the PHP code in the first line of the code. But I need to place it in EVERY SINGLE page of my site, so it would be best to place it in the sessions.php file, a file which is included in every single page of my site.
Even thought my script code is the first thing in the sessions.php, it doesn't work.
I've read somewhere that Output Bufferring functions could save me here, but I dunno how to use it, where to place the functions. Here's my sessions.php file:
<?php
// URL Redirect Function
$url = $_SERVER['REQUEST_URI'];
$url_boolean = strpos($url, '.php');
$url_extensionless = str_replace('.php', '', $url);if ($url_boolean == TRUE) {
header("Location: http://www.example.com{$url_extensionless}");
exit;
} else { }// My Sessions Handling Functions Goes Here
...
?>
Please help. Thank you very much!
[edited by: dreamcatcher at 7:03 am (utc) on April 14, 2008]
[edit reason] Use example.com, thanks. [/edit]
By chance is your sessions.php file being included in another file? If that is the case your include for sessions.php should be the first include and nothing can be before that...
IE - (example - index.php);
<?
include('options/settings.php');
include('options/session.php');
?>
This would generate a headers already sent error. Where:
<? include('options/session.php');
include('options/settings.php');
?>
would not generate headers already sent...but...yes there is a but...if your settings.php has any redirect instructions then you will run into the same problem.
A suggestion as I don't know if you are even using includes.