Jump to content

Recommended Posts

I have a 'folder security" piece that I had written several years ago. It tracks log-ins and who/when people have logged in, etc. Then in any file in that folder you want secure, you:

<?php include_once("security/MYsecurity.php"); ?>

As the first line of that file. This contains various things like info on how to check for allowed users, etc.

 

The biggest point here is that I've used this "code" (which used 2-3 pages of stuff to do what  it does) on at least 5 or 10 websites in the last 3 years. I've not had any problem till now.

 

I set it up on a host where I've never used it before. When I go to the page- just browsing, not logged in yet, I get this error:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/www/vhosts/MYSITE.com/httpdocs/datatube/security/MYsecurity.php:1) in /var/www/vhosts/MYSITE.com/httpdocs/datatube/security/MYsecurity.php on line 81

 

In the first place, I used the code from a site I just set up a few weeks ago (that doesn't show this error). I've used a program to compare to compare this file to the last one I set up. Other than the obvious differences in DB/Table/field names (that I've verified), there are no structural differences.

 

Any guesses on why on one(many) host(s), this would work "perfectly", then on another host, it would break?

 

Is it site structure? The way they handle something else?

 

I'm reluctant to post the code for several reasons;

1- I've verified that there are no differences that should matter

2- There are several pages of code.

3- There are portions that I would have to significantly edit to post.

 

So I'm just trying to see if anyone has any ideas why this might be happening, or suggest something to ask Tech Support?

Why? I dont know. But a possible solution (cant see your code so its hard to say for sure) is to move your session_start() to somewhere before the include. The headers are being sent somewhere in the include, so if you have your session_start() before that point, theoretically the headers should not have been sent yet.

Haku, I believe the session is being set in that include. Here's an example page:

 

<?php include_once("security/Mysecurity.php"); ?>
<?php $DOCROOT = $_SERVER['DOCUMENT_ROOT'] ; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>private data management- your IP has been recorded.</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="GOOGLEBOT" CONTENT="NOARCHIVE">
    <META NAME="ROBOTS" CONTENT="NONE">
    <LINK REL="stylesheet" TYPE="text/css" HREF="CSS/SEC.css">

</HEAD>

<BODY><H1>Please choose...</H1>
	  <a name="top"></a>
<P>
<!-- search code and form from http://php.about.com/od/phpwithmysql/ss/php_search_2.htm -->
<?php
if (!empty($_REQUEST["id"])) {
   echo "<center><FONT color=\"#ff0000\"><B>Record Updated</B></FONT></center>";
}
if (!empty($_REQUEST["del"])) {
   echo "<center><FONT color=\"#ff0000\"><B>Record Deleted</B></FONT></center>";
}
?>
<center><div style='width:100%; background-color:silver; text-align:right'>
<?php SECShowAdminLink(); ?>
   
<?php SECShowLogoutLink(); ?>    
</div></center>
<center><div style='width:100%; background-color:#ffe4c4; text-align:center'><BR>
<A href="#top"><IMG src="images/uparrow.gif" border="0" hspace="2" vspace="4" /></A><A href="#bottom"><IMG src="images/downarrow.gif" border="0" hspace="4" vspace="4" /></A> Up/Down arrows on pages will take you to the top of bottom of the page.<BR><BR></div></center>
<!-- *********************************************************** -->
<form name="search" method="post" action="<?=$PHP_SELF?>">
<P>Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="SongTitle">Song Title</option>
<Option VALUE="ArtistPrimary">Artist Primary</option>
<Option VALUE="ArtistSecondary">Artist Secondary</option>
<Option VALUE="WriterPrimary">Writer Primary</option>
<Option VALUE="WriterSecondary">Writer Secondary</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" /></P>
</form>
<!-- *********************************************************** -->
<?php

//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
include "include/footer.php";
exit;
}

// Otherwise we connect to our Database
include("dbinfo.inc.php");
//mysql_connect("localhost", "director", "sher!0ck");
mysql_connect($dbhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM SongList WHERE upper($field) LIKE'%$find%'");
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find; echo " <A href=\"#top\"><IMG src=\"images/uparrow.gif\" border=\"0\" hspace=\"2\" vspace=\"4\" /></A><A href=\"#bottom\"><IMG src=\"images/downarrow.gif\" border=\"0\" hspace=\"4\" vspace=\"4\" /></A><br><table border=\"1\" cellspacing=\"2\" cellpadding=\"3\">";
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo "<TR><TD valign=\"top\">";
echo $result['id'];
echo "</TD><TD valign=\"top\">";
echo $result['SongTitle'];
echo " ";
echo $result['ArtistPrimary'];
echo "</TD><TD valign=\"top\">";
echo $result['ArtistSecondary'];
echo "</TD><TD valign=\"top\">";
echo $result['WriterPrimary'];
echo "</TD><TD valign=\"top\">";
echo $result['WriterSecondary'];
echo "</TD><TD valign=\"top\">";
echo "<a href='search_edit.php?id=".$result['id']."''>edit</a></TD>";
echo "<TR>";
}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "</TABLE>";
//And we remind them what they searched for
echo "<b>Searched For:</b>" .$find;
echo " <A href=\"#top\"><IMG src=\"images/uparrow.gif\" border=\"0\" hspace=\"2\" vspace=\"4\" /></A><A href=\"#bottom\"><IMG src=\"images/downarrow.gif\" border=\"0\" hspace=\"4\" vspace=\"4\" /></A>" ;
}
?>

<!-- *********************************************************** -->
<?php include "include/footer.php"; ?>	
	  <a name="bottom"></a>
	  </BODY>
</HTML>

 

Schilly: I did have a couple lines where the PHP start did have a space or two before the tag. Two issues:

1- the other pages that work have them too.

2- I removed them and have the same error showing.

A header sent message referring to line 1 (see the error message you posted) either means that there is white space before the opening <?php tag or the file was saved in UTF-8 format and the BOM characters (search if you don't know what that means) at the start of the file are output as content to the browser and prevent the headers from working.

 

Save your file as plain ANSI/ASCII instead of UTF-8.

Some php configurations have output buffering on by default in the php.ini, which tends to mask problems instead of solving them. So, you end up with code that appears to work on one server but not another.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.