gpt4 book ai didi

javascript - 甜蜜警报不适用于 $_session

转载 作者:行者123 更新时间:2023-11-29 03:24:05 27 4
gpt4 key购买 nike

如果 sql 为真,我想显示一个甜蜜的警报,但它不起作用。这是后端部分。

<?php
include "../../../config/config.php";

if (isset($_POST['submit-slider']))
{
$title = $_POST['title-slider'];
$description = $_POST['description-slider'];
$street = $_POST['street-slider'];
$phone = $_POST['phone-slider'];
$trip = $_POST['trip-slider'];
$web = $_POST['web-slider'];
$email = $_POST['email-slider'];

$target_dir = "../../../img/homepage/screen_4/";
$target_file2 = "" . basename($_FILES["img-slider"]["name"]);
$target_file = $target_dir . basename($_FILES["img-slider"]["name"]);


$uploadOk = 1;

$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);


// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
// header("Location: /dashboard/views/slider/add_slider.php");
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["img-slider"]["tmp_name"], $target_file)) {


//echo "The file ". basename( $_FILES["img"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}


$query = "INSERT INTO images(title,
description,
street_1,
phone,
url,
trip_link,
img,
email
)

VALUES ('" . $title . "', '"
. $description . "', '"
. $street . "', '"
. $phone . "', '"
. $web . "', '"
. $trip . "', '"
. $target_file2 . "', '"
. $email . "')";

$result = mysqli_query($con, $query);

if ($result) {

$_SESSION['succes_slider'] = 1;
header("Location: /dashboard/views/slider/add_slider.php");
} else {
// $_SESSION['succes_slider'] = 0;
header("Location: /dashboard/views/slider/add_slider.php");
}
}
}
?>

这是我要显示甜蜜警报的页面。

<?php
session_start();
if (!isset($_SESSION['name'])) {
header("Location: /dashboard/login.php");
}


//include "../config/config.php";
include "../../components/header.php";
include "../../components/menu.php";


if (isset($_SESSION['succes_slider']) == 1) {
echo" <script>
$(document).ready(function() {
swal('Succes','','succes');
});
</script>";
}


?>

</aside>


<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Hello
<small>HI</small>
</h1>
</section>

<!-- Main content -->
<section class="content">

我不知道为什么不工作,我知道..我的代码在 MySql 注入(inject)中容易受到攻击,但我现在不在这方面工作。

甜蜜的警报在我的登录页面上工作,如果可以帮助别人知道为什么在其他页面上不起作用..

这里是登录后台

if (isset($_POST['login'])) {
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);



$sql = "SELECT * FROM users WHERE email='" . $email . "' AND password='" . md5($password) . "'";


$result = mysqli_query($con, $sql);


$row_count = mysqli_num_rows($result);


if ($row_count != 0) {
$row = mysqli_fetch_assoc($result);


$_SESSION['email'] = $email;
$_SESSION['name'] = $row['name'];




header("Location: /dashboard/index.php");
} else {
$_SESSION['error'] = 1;
header("Location: /dashboard/login.php");
}
}

登录的前端与其他页面相同,区别在于 session 的名称。

最佳答案

您应该在使用任何 $_SESSION 之前使用 session_start。此外,我看到您正在使用 include,我建议您改用 require,因为如果您没有文件,它会触发错误。另一个建议是在脚本中包含/要求文件之前检查文件是否存在。

<?php
// include "../../../config/config.php";
// if a file is missing include won't trigger an error
require "../../../config/config.php";

// always include session_start where you plan to use $_SESSION
session_start();

if (isset($_POST['submit-slider']))

关于javascript - 甜蜜警报不适用于 $_session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138163/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com