简体   繁体   中英

Php cannot read secure cookies

Php cannot read secure cookies.

Code(Javascript):

document.cookie = <?php echo '"'.$hCName.'="'; ?> + host + "; path=/; secure; HttpOnly";
document.cookie = <?php echo '"'.$uCName.'="'; ?> + username + "; path=/; secure; HttpOnly";
document.cookie = <?php echo '"'.$pCName.'="'; ?> + password + "; path=/; secure; HttpOnly";
document.cookie = <?php echo '"'.$dNCName.'="'; ?> + dbName + "; path=/; secure; HttpOnly";
document.cookie = <?php echo '"'.$dPCName.'="'; ?> + dbPort + "; path=/; secure; HttpOnly";

Code(Php):

<?php
include_once("../scripts/session_start.php");
$host = $_COOKIE[$_SESSION['hCName']];
$username = $_COOKIE[$_SESSION['uCName']];
$password = $_COOKIE[$_SESSION['pCName']];
$dbName = $_COOKIE[$_SESSION['dNCName']];
$dbPort = $_COOKIE[$_SESSION['dPCName']];
echo "Host: ".$host.", Username: ".$username.", Password: ".$password.", dbName: ".$dbName.", dbPort: ".$dbPort;
?>

Edit: I am getting:

Notice: Undefined index: hCName in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 3

Notice: Undefined index: in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 3

Notice: Undefined index: uCName in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 4

Notice: Undefined index: in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 4

Notice: Undefined index: pCName in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 5

Notice: Undefined index: in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 5

Notice: Undefined index: dNCName in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 6

Notice: Undefined index: in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 6

Notice: Undefined index: dPCName in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 7

Notice: Undefined index: in C:\\Users\\joonas\\Desktop\\Webon cms\\root\\install\\createTables.php on line 7 Host: , Username: , Password: , dbName: , dbPort:

Two points:

  • As Scott Arciszewski points out, HTTP Only cookies cannot be manipulated by JavaScript.
  • Secure cookies are only available when the current protocol is HTTPS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM