A
A
Andrew2015-11-11 23:40:04
PHP
Andrew, 2015-11-11 23:40:04

How to write data to cookie, and how to work with session?

Never encountered cookies. But now the time has come. The task is this: a code is generated on the page from letters and numbers.

<?php
function generate_code($length = 7){
$num = rand(11111, 99999);
$code = md5($num);
$code = substr($code, 0, (int)$length);
return $code;
}
?>

This code must be remembered for a certain number of days (5-7 days). After this time, when you re-enter the page, a new code will be generated.
Tell me where to look, where to start? I don’t think that everything is so complicated here, I just don’t know where and how to start “digging”.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Godmode, 2015-11-11
@Tekcry

php.net/manual/en/function.setcookie.php

$id; // ID юзера из БД
setcookie("TestCookie", $id, time()+604800);  /* срок действия 1 неделя */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question