Md. Maidul Islam
Md. Maidul Islam

Reputation: 574

How to set session & cookie in html?

I know some issue charset, refresh like

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="300">

Can I use like following code? Anyone can help me to give a suggestion

<meta http-equiv="set-session" content="243242">
<meta http-equiv="set-cookie" content="300">

Upvotes: 2

Views: 3263

Answers (2)

Tanner Babcock
Tanner Babcock

Reputation: 3350

Besides the non-conforming <meta> property, you would need either simple JavaScript or PHP, to set and read from cookies. This is a simple way to do it in PHP, although PHP requires some sort of server environment (Apache for example) to run and execute scripts.

<?php

setcookie("name", "Maidul Islam");
echo "<p>Your name is " . $_COOKIE['name'] . ".</p>";

setcookie("date", "2018-01-21");
echo "<p>The date is " . $_COOKIE['date'] . ".</p>";

?>

Upvotes: 1

ild flue
ild flue

Reputation: 1361

You can use Javascript to create / set cookie, such as

<script>
document.cookie = "username=Maidul Islam";
</script>

It is not possible to create / set session through HTML or Javascript.

Upvotes: 1

Related Questions