Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL 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 October 23rd, 2004, 01:09 AM
Authorized User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session Error in PHP

I have a problem with my session in PHP with code like these :
cek_login.php

<?
    session_start();
    session_register("username");
    if ((!$username) or (!$pass))
    {
        echo "Login tidak lengkap ";
    }
    else
    {
        $koneksi = mysql_connect("localhost", "", "") or die (mysql_error());
        mysql_select_db("latihan_php");
        $passwd = md5($pass);
        $query_login = mysql_query("select count(*) as login from anggota where username= '$username' and pass = '$passwd'") or die (mysql_error());
        $row = mysql_fetch_array($query_login);
        if ($row["login"] == "1")
        {
            session_register("username");
            header("location:member.php");
        }
        else
        {
            header("location:non_member.php");
        }
    }
?>

When I login form login.html and click submit button there are error messages like these :


Warning: Cannot send session cookie - headers already sent by (output started at C:\apache\htdocs\latihan_session\cek_login.php:12) in C:\apache\htdocs\latihan_session\cek_login.php on line 13

Warning: Cannot send session cache limiter - headers already sent (output started at C:\apache\htdocs\latihan_session\cek_login.php:12) in C:\apache\htdocs\latihan_session\cek_login.php on line 13

Warning: open(/tmp\sess_c3b315c71b5b79f890ef0f993ee3073a, O_RDWR) failed: m (2) in C:\apache\htdocs\latihan_session\cek_login.php on line 13
Login tidak lengkap
Warning: open(/tmp\sess_c3b315c71b5b79f890ef0f993ee3073a, O_RDWR) failed: m (2) in Unknown on line 0

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

Some one help me, please !!!!

Best regard,

Randhy

 
Old October 24th, 2004, 08:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Are there any lines left above the code that you posted here? If so, move the session_start(); to the top of this page. This should be the first line of code on your page.

Try this simple example.
Code:
<?
session_start();
$_SESSION['abc'] = "hello world";?>
<html>
<head>
<title>test session</title>
</head>
<body>
<? echo "The content of sess variable is $_SESSION['abc']";?>
</body>
</html>
Try to play around with this by adding some lines on top of this page and see how that behaves.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 26th, 2004, 06:15 AM
Authorized User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried you code and there are some error messagees again :

Warning: open(/tmp\sess_607eafeccb9a366192f599262a6d3039, O_RDWR) failed: m (2) in C:\apache\htdocs\latihan_session\lat01.php on line 2
The content of sess variable is hello world
Warning: open(/tmp\sess_607eafeccb9a366192f599262a6d3039, O_RDWR) failed: m (2) in Unknown on line 0

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


Best Regards,

Randhy

 
Old October 26th, 2004, 06:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What is the OS that you use? Unix/linux/Windows?

_________________________
- Vijay G
Strive for Perfection
 
Old October 26th, 2004, 06:26 AM
Authorized User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Windows XP Professional edition.

 
Old October 26th, 2004, 06:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Okay, look for php.ini under PHP installed folder, and that should be having session.save_path that defaults to the UNIX '/tmp' folder, which you got to uncomment(if commented) and change it to point to Windows TEMP folder.

That should solve this problem.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 29th, 2004, 06:47 AM
Authorized User
 
Join Date: Aug 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have replaced the value of session.save_path to be : C:\Documents and Settings\mahasiswa\Local Settings\Temporary Internet Files, but the cookie is still have errors.

Warning: Cannot send session cookie - headers already sent by (output started at C:\apache\htdocs\latihan_session\cek_login.php:12) in C:\apache\htdocs\latihan_session\cek_login.php on line 13

Warning: Cannot send session cache limiter - headers already sent (output started at C:\apache\htdocs\latihan_session\cek_login.php:12) in C:\apache\htdocs\latihan_session\cek_login.php on line 13

Best reagrds,

Randhy

 
Old October 30th, 2004, 01:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

So you are out of that error now.

setcookie() defines a cookie to be sent along with the rest of the
header information. Cookies must be sent before any other headers are
sent (this is a restriction of cookies, not PHP). This requires you to place calls to this function before any <html> or <head> tags.

And see to that you don't leave unnecessary extra carriage returns at the top.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old December 17th, 2004, 07:49 AM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to LogicalDevloper
Default

<html>
 <Head> An online Banking System</Head>
<br />
<b>Warning</b>: session_start(): open(/tmp\sess_d27d55cebff708ee57c525dab324332b, O_RDWR) failed: No such file or directory (2) in <b>C:\apache\htdocs\beebaho\devSite\userLogin1.php </b> on line <b>6</b><br />
<br />
<b>Warning</b>: session_start(): Cannot send session cookie - headers already sent by (output started at C:\apache\htdocs\beebaho\devSite\userLogin1.php:3) in <b>C:\apache\htdocs\beebaho\devSite\userLogin1.php </b> on line <b>6</b><br />
<br />
<b>Warning</b>: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\apache\htdocs\beebaho\devSite\userLogin1.php:3) in <b>C:\apache\htdocs\beebaho\devSite\userLogin1.php </b> on line <b>6</b><br


same prob any solution

The impossible does not exist





Similar Threads
Thread Thread Starter Forum Replies Last Post
session error - php.ini file bogins Beginning PHP 8 January 5th, 2008 04:59 PM
PHP session cookie ajit Beginning PHP 0 October 23rd, 2007 11:56 PM
PHP Session error anmolnandha Beginning PHP 1 November 29th, 2006 11:06 PM
Session Error / PHP.ini file socoolbrewster Beginning PHP 5 June 8th, 2006 04:18 AM
How do i handle session variables in php goutamj PHP How-To 2 July 27th, 2005 08:37 PM





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