当我使用php post函数时,它将删除我的会话cookie,而不受我的控制

时间:2019-06-01 00:10:00

标签: php cookies

当我的用户登录页面时,我设置了一个用户cookie,它可以正常工作。另外,我在所有页面上放置了一个脚本来检查cookie。但是,当我使用php post脚本时,我的cookie被删除,系统会自动将我发送回登录页面。您对这种情况有任何想法吗?

我试图在我的post.php脚本中再次设置cookie,但是它不起作用。

'

<?php
    include 'config.php';


$blok_header = filter_input(INPUT_POST,'blok_header');
$blok_text = filter_input(INPUT_POST,'blok_text');
$Sayfa_Linkleri = filter_input(INPUT_POST,'Sayfa_Linkleri');

$sl = $_GET["Sayfa_Linkleri"];
    // Veritabanına Ekleyelim.

$guncelle = mysqli_query($conn,"UPDATE example_table
  SET blok_header = '$blok_header' , blok_text = '$blok_text', Sayfa_Linkleri = '$Sayfa_Linkleri' ,guncelle = '$now'
  WHERE Sayfa_Linkleri='$sl'") ;


if($guncelle){
      header("location: http://example.com/example-admin/admin/example_edit.php?Sayfa_Linkleri=".$sl);
}
else{
    echo "Bir Sorun Oluştu";
}
?> 

'

<?php

if(htmlspecialchars($ _ COOKIE [“ kullanici”])== null) {

header("refresh:1;url=http://www.example.com/example-admin");

} ?>

2 个答案:

答案 0 :(得分:0)

<?php
include 'config.php';

if($ _ SERVER [“ REQUEST_METHOD”] ==“ POST”){

  $myusername = mysqli_real_escape_string($conn,$_POST['username']);
  $mypassword = mysqli_real_escape_string($conn,$_POST['password']);

  $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
  $result = mysqli_query($conn,$sql);
  $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  $active = $row['active'];

  $count = mysqli_num_rows($result);

  $cookie_name = "kullanici";
  $cookie_value = $myusername;


  if($count == 1) {
     header("location: admin/");
     echo"<div class=\"alert\">
     <span class=\"closebtn\" onclick=\"this.parentElement.style.display='none';\">&times;</span>
     <strong>Hoşgeldiniz!</strong> Giriş başarılı.
   </div>";
   setcookie($cookie_name, $cookie_value, time() + (86400), "/");
  }else {
     header("location: index.php");
     echo"<div class=\"alert\">
     <span class=\"closebtn\" onclick=\"this.parentElement.style.display='none';\">&times;</span>
     <strong>Hata</strong> Kullanıcı adı veya şifre hatalı.
   </div>";
  }

} ?>

答案 1 :(得分:0)

我找到了问题并解决了。如果有人看到相同的问题,我的问题就是

header("location:  http://examplesite/example-admin/admin/some.php");

我把它变成了

header("location: ../../some.php");

成功了!