Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2004, 10:54 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default how to setup the session data

hi,please help me solve this problem.

error message:
Warning: session_start(): open(/tmp\sess_7b62efce76a65e4d203439b5c06670b5, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 3

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php: 3) in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 3

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php: 3) in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 3

Warning: main(common_db_only.php): failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 5


what is wrong?
attach code:

<?php
session_unset();
session_start();

include("common_db_only.php");

if ($page==1)
{

$q1 = "Select * from pentadbir where adm_id='$txtpassword' AND adm_namapguna='$txtlog' and adm_statususer='A' ";
$r1=pg_send($q1);
$count1 = pg_numrows($r1);

if($count1==1)
{


    $values=pg_fetch_array($r1,0,PGSQL_ASSOC);
    $gaji = $values['adm_nogaji']."";
    session_register('gaji');
    //echo "Hi";
    echo "<script language='Javascript'>location='/POT/permohonan/borang_kemaskini_cari.php'</script>";
    exit;
}
    else
{
     echo "<script language='Javascript'>location='/POT/login/loginadmin.php?status=1'</script>";
    // exit;

}
    
} // page=1





?>

<html>
<head>
<title>E-Procurement</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">

function Pengesahan(frm_login)
{
var ErrorMsg = ""
var ErrFlag = "False"


if (frm_login.txtlog.value == "")
{
ErrFlag = "True"
ErrorMsg +="* Please enter username. \n"
}


if (frm_login.txtpassword.value == "")
{
ErrFlag = "True"
ErrorMsg +="* Please enter password. \n"
}

if (ErrFlag == "True")
{
alert(ErrorMsg)
return false
}
else
return true



}
</script>


</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="750" border="0" bgcolor="#000099" align="center" cellpadding="0" cellspacing="0" background="/POT/images/design05.jpg" height="89">
<tr>
    <td rowspan="2" width="76" valign="top" height="70">
    </td>
</tr>

</table>

<table width="750" border="2" height="256" align="center" bordercolor="#000066">
<tr>
    <td height="14" bgcolor="#000099" bordercolor="#000099">
     <table width="100%" border="0" bordercolor="#FFFFFF" cellspacing="0" cellpadding="0">
        <tr width="750" height="5">
        
         <td >
            <div align="center"><?
            $tarikh = gmdate('d F Y');

            echo "Today : $tarikh Now : " ;
             ?><script type="text/javascript">
            var d = new Date()
            document.write(d.getHours())
            document.write(":")
            document.write(d.getMinutes())
            document.write(":")
            document.write(d.getSeconds())
            </script></div>
         </td>
        </tr>
     </table>
    </td>
</tr>
<tr>
    <td bgcolor="#FFFFFF" bordercolor="#FFFFFF" height="252">
     <form name="frm_login" method="post" action="loginadmin.php?page=1" onsubmit="return Pengesahan(document.frm_login)" >
        <table width="75%" border="0" align="center" height="154">
         <tr>
            <td colspan="3" height="2">
             <p align="center"><b>ADMINISTRATOR</b>
             </p>
             <?
                if($status==1)
                {
                echo"<b><center> Invalid username and password. <br>Please reenter.";
                echo"</center></b>";
             }
             else
             {
             echo"<b><center>Please enter username and password: </center></b> ";
             }?>
            </td>
         </tr>
         <tr>
            <td width="34%" height="20">&nbsp;</td>
            <td width="2%" height="20">&nbsp;</td>
            <td width="64%" height="20">
             </td>
         </tr>
         <tr>
            <td width="34%" height="17">Username</td>
            <td width="2%" height="17">:</td>
            <td width="64%" height="17">
             <input type="text" name="txtlog" maxlength="20" size="30">
             </td>
         </tr>
         <tr>
            <td width="34%" height="19">Password</td>
            <td width="2%" height="19">:</td>
            <td width="64%" height="19">
             <input type="password" name="txtpassword" maxlength="20" size="30">
             </td>
         </tr>
         <tr>
            <td colspan="3" height="14" align="right">
             <div align="center"> <b>
                <input type="submit" name="Hantar" value="Submit">
                <input type="reset" name="Batal" value="Cancel">
                </b></div>
            </td>
         </tr>
        </table>
     </form>
    
     <div align="center">
        <p>Copyright
         &copy; 2001-2002 PTM, UM. All rights reserved. </p>
        </div>
    </td>
</tr>
</table>
</body>
</html>

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

how to setup the session.save_path?
Thank you.
 
Old April 9th, 2004, 12:21 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi, you need to verify that the session data directory exists and that it has the proper write permissions.

Open php.ini, this file is located at C:\Windows\php.ini, or where ever Windows is installed.
Locate the following snippet:

Code:
; Argument passed to save_handler.  In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this 
; variable in order to use PHP's session functions.
session.save_path = /tmp
Change the value to reflect a valid file path,
I'd suggest: C:\PHP\sessiondata

Save the changes.

Create the sessiondata directory.

Next apply the proper write permissions to the sessiondata directory, if you're using Windows XP, then read this FAQ:
http://p2p.wrox.com/topic.asp?TOPIC_ID=11962

Verify that there is no whitespace or output before the opening <?php delimiter appearing before the call to session_start().

Restart Apache, run your script again.

This should cure all of your session-related errors.

I'd also remove the call to session_unset().. session_unset() destroys all session variables currently set, and actually wouldn't do anything anyway since its called prior to session_start().

Then..
Warning: main(common_db_only.php): failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 5

This error has come up because the program cannot locate the file, verify the file path to common_db_only.php.

Also, a word on your code.. you don't need to post your entire script, please only post the relevant snips and the related errors.

: )
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 9th, 2004, 02:34 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

But i stil have error message:
Warning: main(common_db_only.php): failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 5

Warning: main(): Failed opening 'common_db_only.php' for inclusion (include_path='.;c:\php4\pear') in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\login\loginadmin.php on line 5

how to verify it? can give some example? because php language still new for me.

Thank you so much


 
Old April 9th, 2004, 04:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, the error you're getting is that the file "common_db_only.php" is not found. You should check that this file exists and that PHP has permission to read it.


Take care,

Nik
http://www.bigaction.org/
 
Old April 19th, 2004, 11:04 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

How about this error message? what is mean?
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php on line 3

code attach:
 <?

session_start();
include("common.php");


$conn = pg_open();

?>
<?php
/*insert values*/
if ($status==1)
{
     $query="select * from jabatan";
    $result=pg_exec($conn, $query) or die("Error in query: $query." .pg_last_error($conn));
    $rows = pg_numrows($result);


    $query1="select * from e_pengumuman";
    $result1=pg_exec($conn, $query1) or die("Error in query: $query1." .pg_last_error($conn));
    $rows1 = pg_numrows($result1);


    //form submitted
    //prepare to insert data
    //database access parameters

    for ($k=0; $k<$rows1; $k++)
    {
        $row1=pg_fetch_object($result1, $k);
    }
    $numrow=$row1->ep_id;


    {
        $numrow=$numrow+1;


        $query04="insert into e_pengumuman values('$numrow', '$addressField', 'PTM', '$dc1', '$dc2', '$ep_tajuk', '$ep_kandungan')";
        $dbres1=pg_send($query04);
    }
}
?>

thank you so much.
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php on line 3



 
Old April 20th, 2004, 12:22 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by junemo
 How about this error message? what is mean?
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php:1) in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php on line 3
session_start alters the outgoing HTTP headers that are sent out to the browser with every page request. In this function it sends out a cookie containing the session id. The HTTP headers must be sent before any content from the page, e.g. HTML code. Make sure that no whitespace appears before the opening <?php delimiter and that there is no other output after the <?php delimiter and before the call to session_start.

hth,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 20th, 2004, 01:03 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi Rich,
First, i feel so sorry because i still not understand about it. Can you change the code for me?

thanks.

 
Old April 20th, 2004, 01:13 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by junemo:

First, i feel so sorry because i still not understand about it. Can you change the code for me?
See the one single whitespace before the opening <?php delimiter? BTW, use <?php don't use <?.
Code:
Output before the call to session_start() is bad!  This can be text like this, HTML code, a single whitespace, a newline character.  Nothing!  I don't know how more clearly to put it.

Bad: 
 <?php

Good:
<?php

session_start();
include("common.php");


$conn = pg_open();

?>
hth,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 20th, 2004, 02:17 AM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

hi Rich, thanks....
umm... but my code still have error:

Fatal error: Call to undefined function: pg_open() in C:\Program Files\Apache Group\Apache2\htdocs\pro\POT\general_info\newannou nce1.php on line 7
I hope you're not boring reply me and teach me the php. This is my first time to use the php for my training project.

Thanks a lot and have a nice day.
junemo.


 
Old April 20th, 2004, 02:51 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

pg_open is a user-defined function. You need to define the function in order for it to work. Meaning that, it is not a pre-defined function, pre-defined functions are those that are already available in PHP or via one of PHP's extensions. When you try to use a function and it isn't defined PHP chokes, it throws a E_FATAL level error and execution haults. pg is the prefix for PostgreSQL functions, but pg_open isn't a valid PostgreSQL function. Perhaps you mean to use pg_connect there, and if so not only do you need that function but you need to pass the required arugments to it as well.

See:
http://www.php.net/pg_connect

Its always helpful to read the manual!
http://www.php.net/manual

hth,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reporting for Analytical Data Setup nickLogan BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 January 21st, 2008 02:17 PM
How to pass data to user interface (.NET Setup) saeedahmed C# 2 November 10th, 2005 06:48 AM
Writing Data into database from a Session Lofa ASP.NET 1.0 and 1.1 Basics 0 October 9th, 2005 08:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.