hi everyone,

I have found one warning in my php code. How it can be removed.
pls help me . It is very urgent.

warning is like this on a php page.........

Warning: session_start() [function.session-start]: open(/tmp/php-ses/sess_7dbaf8a556cd076ed8409da8908ea802, O_RDWR) failed: No such file or directory (2) in /home/vg002web01/12/46/1014612/web/login/user.main.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/vg002web01/12/46/1014612/web/login/user.main.php:2)


Pls help me.
Thanks
gagan

It is because you have output something to the browser before session_start(). Below is an example of what to do:

<? session_start(); ?>
<html>
More browser output.
<?
//now php code
?>

Below is an example of what not to do:

<html>
<? session_start();
//php code
?>

As you can see, in the correct example, the first 2 characters/letters in the text file is the php opening bracket <? and is immediately followed by session_start(); However session_start() may also be on line 2. That is the easiest way for a session newbie to avoid the error as headers need to be sent before browser output and session_start() is a header.

Hi sir ,,

Thanks for reply

But i have already written code like this

<?php
  session_start(); 
 if ($_SESSION["login"]!="T")
{
	   
	 header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/myindex.php'); 
} 
  
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> Login -  Ward, Damon and Posner, P.A.</title>
<meta name="keywords" content="">
<meta name="description" content="">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="/stylie.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.inputbox {border:1px solid #dfdfe3}
.inputbox1 {border:1px solid #dfdfe3; height:22px;}
.text{font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333333; text-decoration:none;}
.text:hover{font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#000033; text-decoration:underline;}
-->
</style>
<script type="text/javascript">
    var GB_ROOT_DIR = "http://www.warddamon.com/greybox/";
</script>

<script type="text/javascript" src="../greybox/AJS.js"></script>
<script type="text/javascript" src="../greybox/AJS_fx.js"></script>
<script type="text/javascript" src="../greybox/gb_scripts.js"></script>
<link href="../greybox/gb_styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

<? include ("../includes/header.php"); 
?>
<link href="../stylie.css" rel="stylesheet" type="text/css" />
<table width="725" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"><img src="../img/topbeam.gif" width="725" height="21"></td>
  </tr>
  <tr>
    <td width="23" style="background-image:url(../img/lefty.gif)"><img src="../img/lefty.gif" width="23" height="10"></td>
    <td width="679" bgcolor="#FFFFFF"><table width="679" border="0" cellspacing="0" cellpadding="0">
      <tr><td width="189" valign="top" style="background-image:url(/img/side_nav.jpg)">
        <? include ("../includes/leftnav2.php"); ?></td>
        <td width="490" align="center" bgcolor="#F2F3E2">
		<table width="490" border="0" cellspacing="0" cellpadding="0">
		 
          <tr>
            <td><img src="Client-Login.jpg" width="490" height="60"></td>
          </tr>
		
          <tr>
            <td style="background-image:url(../img/content_back.jpg)"><br><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="4%">&nbsp;</td>
                  <td width="88%"><table width="100%"  align="center" border="0">
<tr>
<td valign="top">

  <fieldset>
    <legend><FONT SIZE="2" COLOR="#6F7542" face="verdana"><B><I>Admin Panel</I></B></FONT></legend>
	<table width="100%" height="100%" align="center" border="0" cellpadding="10">
		<tr>
	<td align="center"><a href="user.select.php" class="text">
	<IMG SRC="images/icon_affiliate_management.gif" BORDER="0" height="56" width="59" ALT="Manage Clients">
	<br> <b>Add & Update Clients</b></a>
	</td>
		<td align="center"><a href="user1.select.php" title="WARD DAMON & POSNER" rel="gb_page_center[500, 500]" class="text">
		<IMG SRC="images/catalogs2.gif" BORDER="0" height="60" width="60" ALT="View Homeonwer Details">
	<br><b>View Homeonwer Details</b></a>
	</td><td align="center"><A HREF="logout.php" class="text">
	<IMG SRC="images/logout.gif" WIDTH="71" HEIGHT="59" BORDER="0" ALT="Logout">
	<br><b>Logout</b></a></td>
</tr>


  </fieldset>

</td>
</tr>
</table>

</table></td>
                  <td width="4%">&nbsp;</td>
                </tr>
              </table>
             </td>
          </tr><tr><td height="130"></td></tr>
          <tr>
            <td><a href="http://www.warddamon.com/"><img src="content_footer_terms.jpg" alt="return to the homepage of warddamon.com" width="490" height="25" border="0"></a></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </td>
    <td width="23" style="background-image:url(../img/righty.gif)"><img src="../img/righty.gif" width="23" height="10"></td>
  </tr>
  <tr>
    <td colspan="3"><img src="../img/btmbeam.gif" width="725" height="21"></td>
  </tr>
</table>
<? include ("../includes/footer.php"); ?>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

But warning is coming ..........so tell me the reason how i will have to write this code so that i can avoid this warning.

Please help me
Thanks
gagan

I guess, you don't have enough permissions on tmp directory. Give all the permissions to tmp directory and try again. When you use session_start, it will create a cookie if this option session.use_cookies is turned on.

With that extra info, now I see why that second error occurs. The first error may be caused by insufficient permissions like nav33n said then when the session header passes through the default settings, it then causes the second error because the browser output is the error message. And it is that brouser output that causes the header error for the second error message.

So basically if you can solve the first error message then the second will solve itself. Also, to add to the info nav33n has presented, depending on your host, you may be able to find the tmp directory through your ftp/upload client/program. Generally it is located at the base of what you can browse through your ftp client. So it is not inside the public_html folder but may be in the same parent directory. Then as I have read about some hosts, they do not allow full permissions. This is so that the directory does not run as anonyms and instead runs as the server. To explain in more detail, some host only allow a maximum chmod of 755. And from an article I have read, servers with phpsuexec installed will have that maximum chmod. In case you didn't know, the chmod is the overall number of the permissions you have assigned to a file or directory. So be aware of that possible limitation.

Hope it explains.

I guess, you don't have enough permissions on tmp directory. Give all the permissions to tmp directory and try again. When you use session_start, it will create a cookie if this option session.use_cookies is turned on.

thanks for reply,

can u please tell me where is this temp directory . or how i can found this directory in my system. and how i can give it permissions

thanks,

Check php.ini and find the session.save_path. Make sure that the file mentioned exists and is writable

With that extra info, now I see why that second error occurs. The first error may be caused by insufficient permissions like nav33n said then when the session header passes through the default settings, it then causes the second error because the browser output is the error message. And it is that brouser output that causes the header error for the second error message.

So basically if you can solve the first error message then the second will solve itself. Also, to add to the info nav33n has presented, depending on your host, you may be able to find the tmp directory through your ftp/upload client/program. Generally it is located at the base of what you can browse through your ftp client. So it is not inside the public_html folder but may be in the same parent directory. Then as I have read about some hosts, they do not allow full permissions. This is so that the directory does not run as anonyms and instead runs as the server. To explain in more detail, some host only allow a maximum chmod of 755. And from an article I have read, servers with phpsuexec installed will have that maximum chmod. In case you didn't know, the chmod is the overall number of the permissions you have assigned to a file or directory. So be aware of that possible limitation.

Hope it explains.

Hi sir,

i have done every effort to remove this warning . but i am unable to resolve this it. At last when i have made comments this line session_start(); then i am not facing such warning.

I have also done changes in php.ini file . It was before session.save_path = "c:/wamp/tmp" but i have made it alos like this
session.save_path = "c:/wamp/tmp/php-ses/" but still the problem is same.

so pls help me why the problem is coming . i have already post the code of this file where the error is coming.

Thanks,
Gagan

By the looks of the location it seems you are using wamp and when accessing the files under localhost the permissions shouldn't make a difference. Another thing, are you using notepad? If not then open the file in notepad then delete the first line without the mouse and replace the first line. By saying without the mouse, I mean to click at the end of the line then to hold down the keyboard backspace key for about 5 seconds or untill you hear a constant beaping noise. Then retype in the first line in notepad. BTW notepad is a program that comes with windows. Then save the file and see if that works. The reason is that this issue can be because your text file editor is adding extra binary data to the beginning of the file and notepad will be able to detect this binary data weather it is as invisible characters or weared symbols. Another way to test if this is the case is to make a file with the following using your regular editor and see if it too reports an error:

<?
session_start();
?>

By the looks of the location it seems you are using wamp and when accessing the files under localhost the permissions shouldn't make a difference. Another thing, are you using notepad? If not then open the file in notepad then delete the first line without the mouse and replace the first line. By saying without the mouse, I mean to click at the end of the line then to hold down the keyboard backspace key for about 5 seconds or untill you hear a constant beaping noise. Then retype in the first line in notepad. BTW notepad is a program that comes with windows. Then save the file and see if that works. The reason is that this issue can be because your text file editor is adding extra binary data to the beginning of the file and notepad will be able to detect this binary data weather it is as invisible characters or weared symbols. Another way to test if this is the case is to make a file with the following using your regular editor and see if it too reports an error:

<?
session_start();
?>

yes sir i am still getting error if i will type code as u asked me . then what i should do pls tell me .
is this problem in my sever or system . As after doing so efforts ,
i am thinking there will be problem in client's sever means where i am uploading this php file.
did you understand very well. If there is any doubt then pls tell me.
If u have any other solution means if we will no write session in our file and then what will be another solution for that we could authorisatiion of page to only few person. If u have any idea about that then send me.
thanks for reply,
Gagan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.