PHP问题“无法发送会话Cookie” [英] PHP issue "Cannot send session cookie"
问题描述
请附上我的代码:
<?PHP
session_start();
if (isset($_POST["usernameform"])){
$username = $_POST['usernameform'];
$password1 = $_POST['passwordform'];
$user_name = "XXXX";
$password = "XXXXX";
$database = "XXX";
$server = "XXXX";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$SQL = "SELECT * FROM login WHERE Username = '$username' AND Password = '$password1' "; //grab all the records from table
$result = mysql_query($SQL)
or die("Error:" . mysql_error());
if (mysql_num_rows($result) > 0){ //if username and password match return number of rows is always 1
$_SESSION['login'] = $username; //by placing this in session it will remember this variable on the page it directs too
while ( $row = mysql_fetch_assoc($result) ){ //lays out array in $result
$_SESSION['ID'] = $row['ID']; //selects from list of array ID
$_SESSION['firstname'] = $row['First_Name'];
echo'<script> window.location="page1.php"; </script> ';
}
} else {
$_SESSION['login'] = '';
print('
<script type="text/javascript"> //place html script for alert. Use single comma for print command here.
alert("Sorry, your username or password could not be recognized")
</script>
');
session_destroy();
}
}
?>
虽然代码在我的localhost(wampserver)上工作得很好,但它不能在我的主机和我的主机上工作获取错误:
Although the code works perfectly on my localhost (wampserver), it does not work on my host and I get the errors:
警告:session_start()[function.session-start]:无法发送会话
cookie - 在第2行的/.../vhindex.php中发送(输出开始于
/.../vhindex.php:1)
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /.../vhindex.php:1) in /.../vhindex.php on line 2
警告: session_start()[function.session-start]:无法发送会话
缓存限制器 - 已经发送的头文件(输出开始于
/.../vhindex.php:1)in /.../vhindex .php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /.../vhindex.php:1) in /.../vhindex.php on line 2
session_start();
在PHP块的顶部,在任何HTML输出之前,我完全被困住。
The session_start();
code has been placed at the top of the PHP block and before any HTML output is made and I am completely stumped.
任何想法?
推荐答案
- 下载记事本++ 并打开该文件,删除
<?PHP $之前的所有花式字符c $ c>
- 确保在
<?PHP
之前没有像或tab或linebreak之类的空白字符。
- 在记事本++中,点击
编码
,然后UTF-8没有BOM
将文件转换为UTF-8而不使用BOM,然后保存。 - Download Notepad++ and open the file there, delete all fancy characters before the
<?PHP
- Make sure there is no whitespace character like " " or tab or linebreak before the
<?PHP
.- In Notepad++ click
Encoding
and thenUTF-8 without BOM
to convert the file to UTF-8 without BOM, then save it.
这篇关于PHP问题“无法发送会话Cookie”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- In Notepad++ click
- 在记事本++中,点击