在表单页面上,我有以下内容:
<?php
session_start();
if (isset($_POST['submit'])){
$_SESSION['username'] = $_POST['username'];
}
?>
<form action="index.php">
<input type="text" name="username">
<input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
在文件“index.php”上,我有:
<?php
session_start();
echo ($_SESSION['username']);
?>
Run Code Online (Sandbox Code Playgroud)
但是索引页面上的输出表明会话变量未定义。我该如何解决这个问题,为什么它是未定义的?
我知道这已被问了一千次,我仍然找不到mey错误.
<body><?php
$con = mysql_connect("xxxxxxxxx","xxxxxxxxxxx","xxxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxxxx", $con);
$sql="INSERT INTO mytable (row1, row2)
VALUES
('$_POSTrow1]','$_POST[row2]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("Location: compsubmit.php}");
mysql_close($con)
?></body>
Run Code Online (Sandbox Code Playgroud) 新手来了,
这足以/安全地让人们远离我的管理面板吗?
<?php if (isset($_SESSION["AccountLevelStandard"])) {
echo "<script>location.href='home.php'</script>";
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
PHP 已发送的标头
为什么我不能摆脱这个错误:警告:无法修改标头信息 - 标头已经发送(输出开始于 /Applications/XAMPP/xamppfiles/htdocs/login.php:43)在 /Applications/XAMPP/xamppfiles/htdocs /login.php 第 24 行
第 24 行是带有简单括号的行。我寻找了额外的空格,因为这些是导致此错误的常见原因(从我读过的内容来看),但我找不到任何空格。有任何想法吗?
这是我的代码:
<?php
$check = 0;
if (isset($_POST['submit']))
{
$username = htmlentities($_POST['name']);
$username = strtolower($username);
$password = htmlentities($_POST['apw']);
$filename = getcwd() . "/passwd.txt";
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
foreach($lines as $key => $line)
{
list($name, $pw) = explode(':', $line);
if($name == $username && $pw == $password)
{
$check++;
break;
}
}
if ($check == 1){
checkifPlayed($username);
}
else{
printf("Your username or password are invalid. …Run Code Online (Sandbox Code Playgroud) 可能重复:
PHP已发送的标头
我有一个创建文件的功能.如果成功,我希望它将用户重定向到X页面..在这种情况下1.php ....但它不起作用.PHP脚本位于顶部...所以技术上说它应该工作
它可以工作,如果我把header ()内部的createFile()函数,但不是如果我把它放在if语句....
<?php
//DB Config File
$dbFile = 'dbconfig.php';
function createfile ($dbFile) {
//Creates File and populates it.
$fOpen = fopen($dbFile, 'w');
$fString .= "<?php\n";
$fString .= "// Database Constants\n";
$fString .= "define(\"DB_SERVER\", \"$server\");\n";
$fString .= "define(\"DB_USER\", \"$username\");\n";
$fString .= "define(\"DB_PASS\", \"$password\");\n";
$fString .= "define(\"DB_NAME\", \"$dbname\");\n";
$fString .= "?>";
fwrite($fOpen, $fString);
fclose($fOpen);
}
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$server = $_POST['server'];
$dbname = $_POST['dbname'];
try {
$db = new PDO …Run Code Online (Sandbox Code Playgroud) 我的服务器根目录中有一个文件:
<?php
header("Location: http://www.google.com/", true); //this does not work
//echo "Test"; //this is tested and works.
?>
Run Code Online (Sandbox Code Playgroud)
我的php.ini文件在某处出错了,为什么会这样?
当我输入用户名和密码时,我收到如下警告:
警告:mysqli_num_rows()期望参数1为mysqli_result,第18行的/home/data/www/z1760359/public_html/group/connectivity.php中给出了数组
和
密码或用户名不正确.
我输入了正确的凭据.我的数据库的结构是:
member ID firstName lastName userName password
Run Code Online (Sandbox Code Playgroud)
这是我的index.php和connectivity.php
的index.php
<?php
session_start();
?>
<html>
<head>
<style>
#login
{
position:absolute;
top: 30%;
bottom: 30%;
left:30%;
right:30%;
margin: 0px auto;
}
</style>
</head>
<body>
<?php
echo"<center>";
echo"<div id=\"login\">";
echo"<form method=\"POST\" action=\"connectivity.php\">";
echo"<b>Username</b> <input type =\"text\" name=\"username\">";
echo"<br/><br/>";
echo"<b>Password</b> <input type =\"password\" name=\"password\">";
echo"<br/><br/>";
echo"<input type=\"submit\" value=\"submit\">";
echo"</div>";
echo"</center>";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
连接
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$host="localhost";
$uname="user";
$pword="";
$db="z1760359";
$conn=mysqli_connect($host,$uname,$pword,$db) or die("Oops something went wrong");
session_start(); …Run Code Online (Sandbox Code Playgroud) <?php
require_once 'connect.php' ;
$sql = "SELECT Title,Date,Time,Location,image_url FROM events ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$data = array();
while($row = $result->fetch_assoc()) {
$data['events'] = $row ;
}
}
echo json_encode($data);
header('Content-Type: application/json');
?>
Run Code Online (Sandbox Code Playgroud) 我的代码 -
if ($result)
{
$row = $result->fetch_object();
$filename = $row->src;
$q = "delete from photos WHERE id=$fileid";
$result = $mysqli->query($q) or die(mysqli_error($mysqli));
if ($result)
{
$filepath = "./images/";
if(fileDelete($filepath,$filename))
{
echo "success";
header("Location: index.php");
exit;
}
else echo "failed";
}
}
Run Code Online (Sandbox Code Playgroud)
输出 -
success Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\pics\deletepic.php:31) in C:\xampp\htdocs\pics\deletepic.php on line 32
所以我试图使用会话......我收到此错误:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home1/####/public_html/####/index.php:3) in /home1/####/public_html/####/index.php on line 4
Run Code Online (Sandbox Code Playgroud)
index.php文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
session_start();
echo $_SESSION['logged_in'];
echo $_SESSION['logged_user'];
?>
<head>
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样?