How to get cookie in php send from Node.js application? I am not fimiliar to php. How to get this cookie creted in nodejs in php?
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.setHeader("Set-Cookie","type-test");
res.setHeader("Year",new Date().getFullYear);
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
My Answer:
To get the cookie created in Node.js in PHP, you can access the cookie in PHP using the $_COOKIE superglobal array. Here's an example of how you can access the "type-test" cookie created in your Node.js application in PHP:
php
// Check if the "type-test" cookie is set
if(isset($_COOKIE['type-test'])) {
// Get the value of the "type-test" cookie
$cookieValue = $_COOKIE['type-test'];
// Output the value of the cookie
echo "Value of 'type-test' cookie: " . $cookieValue;
} else {
echo "Cookie 'type-test' is not set";
}
?>
Make sure to run your Node.js application and then access the PHP file in a web browser to see the value of the "type-test" cookie.
Rate this post
5 of 5 based on 3657 votesComments