Even een probleem met sessie onder PHP.
Ik wil een secure login maken, heb er al een script voor dat ook werkt.
Maar ik krijg allemaal foutmeldingen van sessies.
Volgensmijn ondersteunt mijn locale Apache server geen sessies of iets dergelijks.
Deze foutmelding[en] krijg ik nl.:
-----------------------------------------------------
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\samenstellen\login.php:2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: open(/tmp\sess_e0bd536d5787bd8149eca686fcd1138c, O_RDWR) failed: m (2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Members only. Please login to access this document.
Username:
Password:
Warning: open(/tmp\sess_e0bd536d5787bd8149eca686fcd1138c, O_RDWR) failed: m (2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 0
Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 0
------------------------------------------------------------------------------
en als ik inlog, wat dus wel luk... , krijg ik dezen:
----------------------------------------------------------------------------------
Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\samenstellen\login.php:2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\samenstellen\login.php:2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: open(/tmp\sess_b5165d0e8623e832758744731d5187a5, O_RDWR) failed: m (2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: open(/tmp\sess_b5165d0e8623e832758744731d5187a5, 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
-----------------------------------------------------------------------------------
Dit is het gebruikte script:
------------------------------------------------------------------------------------
<?php
include("dbconnect.php");
?>
<?
session_start(); // start session.
?>
<!-- header tags, edit to match your own, or include template header file. -->
<html>
<head>
<title>Login</title>
<head>
<body>
<?
if(!isset($username) | !isset($password)) {
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Members only. U moet inloggen voor toegang tot dit document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="Login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
// If all is well so far.
session_register("username");
session_register("password"); // register username and password as session variables.
// Here you would check the supplied username and password against your database to see if they exist.
// For example, a MySQL Query, your method may differ.
$sql = mysql_query("SELECT password FROM member WHERE username = '$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $password == $fetch_em["password"]) {
$valid_user = 1;
}
else {
$valid_user = 0;
}
// If the username exists and pass is correct, don't pop up the login code again.
// If info can't be found or verified....
if (!($valid_user))
{
session_unset(); // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Incorrecte inlog gegevens, probeer het opnieuw. U moet inloggen om toegang te krijgen tot dit document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="Login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
?>
---------------------------------------------------------------------------------------
En deze info staat bij sessies als ik gegevens oproep met phpinfo() :
session
Session Support enabled
Directive Local Value Master Value
session.auto_start
Off Off
session.cache_expire
180 180
session.cache_limiter
nocache nocache
session.cookie_domain
no value no value
session.cookie_lifetime
0 0
session.cookie_path
/ /
session.entropy_file
no value no value
session.entropy_length
0 0
session.gc_maxlifetime
1440 1440
session.gc_probability
1 1
session.name
PHPSESSID PHPSESSID
session.referer_check
no value no value
session.save_handler
files files
session.save_path
/tmp /tmp
session.serialize_handler
php php
session.use_cookies
On On
------------------------------------------
De sessies zijn dus wel geenabled.
Hoe kan ik dit probleem oplossen ?
De sessies eruit slopen zou natuurlijk een makkelijke oplossing zijn, maar dat wil ik eigenlijk niet. En ik heb dit probleem al eerder gehad, kon ik de sessies ook niet aan de praat krijgen.
Zeer irritant.
BVD
Jelmer
Ik wil een secure login maken, heb er al een script voor dat ook werkt.
Maar ik krijg allemaal foutmeldingen van sessies.
Volgensmijn ondersteunt mijn locale Apache server geen sessies of iets dergelijks.
Deze foutmelding[en] krijg ik nl.:
-----------------------------------------------------
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\samenstellen\login.php:2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: open(/tmp\sess_e0bd536d5787bd8149eca686fcd1138c, O_RDWR) failed: m (2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Members only. Please login to access this document.
Username:
Password:
Warning: open(/tmp\sess_e0bd536d5787bd8149eca686fcd1138c, O_RDWR) failed: m (2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 0
Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 0
------------------------------------------------------------------------------
en als ik inlog, wat dus wel luk... , krijg ik dezen:
----------------------------------------------------------------------------------
Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\samenstellen\login.php:2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\samenstellen\login.php:2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: open(/tmp\sess_b5165d0e8623e832758744731d5187a5, O_RDWR) failed: m (2) in c:\program files\apache group\apache\htdocs\samenstellen\login.php on line 9
Warning: open(/tmp\sess_b5165d0e8623e832758744731d5187a5, 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
-----------------------------------------------------------------------------------
Dit is het gebruikte script:
------------------------------------------------------------------------------------
<?php
include("dbconnect.php");
?>
<?
session_start(); // start session.
?>
<!-- header tags, edit to match your own, or include template header file. -->
<html>
<head>
<title>Login</title>
<head>
<body>
<?
if(!isset($username) | !isset($password)) {
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Members only. U moet inloggen voor toegang tot dit document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="Login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
// If all is well so far.
session_register("username");
session_register("password"); // register username and password as session variables.
// Here you would check the supplied username and password against your database to see if they exist.
// For example, a MySQL Query, your method may differ.
$sql = mysql_query("SELECT password FROM member WHERE username = '$username'");
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $password == $fetch_em["password"]) {
$valid_user = 1;
}
else {
$valid_user = 0;
}
// If the username exists and pass is correct, don't pop up the login code again.
// If info can't be found or verified....
if (!($valid_user))
{
session_unset(); // Unset session variables.
session_destroy(); // End Session we created earlier.
// escape from php mode.
?>
<form action="<?=$PHP_SELF?><?if($QUERY_STRING){ echo"?". $QUERY_STRING;}?>" method="POST">
<p align="center">Incorrecte inlog gegevens, probeer het opnieuw. U moet inloggen om toegang te krijgen tot dit document.</p>
<table align="center" border="0">
<tr>
<th>
Username:
</th>
<th>
<input type="text" name="username">
</th>
</tr>
<tr>
<th>
Password:
</th>
<th>
<input type="password" name="password">
</th>
</tr>
<tr>
<th colspan="2" align="right">
<input type="submit" value="Login">
</form>
</th>
</tr>
</table>
</body>
</html>
<?
exit();
}
?>
---------------------------------------------------------------------------------------
En deze info staat bij sessies als ik gegevens oproep met phpinfo() :
session
Session Support enabled
Directive Local Value Master Value
session.auto_start
Off Off
session.cache_expire
180 180
session.cache_limiter
nocache nocache
session.cookie_domain
no value no value
session.cookie_lifetime
0 0
session.cookie_path
/ /
session.entropy_file
no value no value
session.entropy_length
0 0
session.gc_maxlifetime
1440 1440
session.gc_probability
1 1
session.name
PHPSESSID PHPSESSID
session.referer_check
no value no value
session.save_handler
files files
session.save_path
/tmp /tmp
session.serialize_handler
php php
session.use_cookies
On On
------------------------------------------
De sessies zijn dus wel geenabled.
Hoe kan ik dit probleem oplossen ?
De sessies eruit slopen zou natuurlijk een makkelijke oplossing zijn, maar dat wil ik eigenlijk niet. En ik heb dit probleem al eerder gehad, kon ik de sessies ook niet aan de praat krijgen.
Zeer irritant.
BVD
Jelmer