Answer the question
In order to leave comments, you need to log in
Why does the submitted form email have a different cookie value?
Hello,
There is a site, we track visitors.
Making a "chel_code" cookie.
<?php
// шапка сайта
$today = time();
$rand = rand(0, 1000);
$chel_code = 'id_'.$rand.'-'.$today;
//создание временной cookie
if(!$_COOKIE["chel_code"]){
setcookie("chel_code", $chel_code, time()+3600);
}
?>
<?php
// форма на стр.
$to = '[email protected]';
$dayMail = strftime("%d.%m.%Y %H:%M:%S %p");
$subject = 'site.ru: '.$dayMail.' Заполнена форма';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: user <[email protected]>' . "\r\n";
if(
(isset($_POST['form_ok']))
&& (!empty($_POST['form_name']))
&& (!empty($_POST['form_email']))
&& (!empty($_POST['form_phone']))
){
$form_surname = (String) trim(strip_tags($_POST['form_surname']));
$form_name = (String) trim(strip_tags($_POST['form_name']));
$form_email = (String) trim(strip_tags($_POST['form_email']));
$form_phone = (String) trim(strip_tags($_POST['form_phone']));
$message = '
<html>
<head>
<title>Заполнена форма </title>
</head>
<body>
<p>на странице <a href="https://site.ru/contacts.php" target="_blank">site.ru/contacts.php</a></p>
<table style="width: 100%;">
<tr>
<td><b>chel_code</b>: </td>
<td>'.$chel_code.'</td>
</tr>
<tr style="background-color: #f8f8f8;">
<td><b>Время</b>: </td>
<td>'.$dayMail.'</td>
</tr>
<tr>
<td><b>ФИО</b>: </td>
<td>'.$form_name.' '.$form_surname.'</td>
</tr>
<tr style="background-color: #f8f8f8;">
<td><b>E-mail</b>: </td>
<td><a href="mailto:'.$form_email.'" title="написать">'.$form_email.'</a></td>
</tr>
</table>
</body>
</html>
';
mail($to, $subject, $message, $headers);
?>
<!-- форма -->
<div class="form_container">
<div class="form_container__wrapper">
<h2 class="form_container__title">Введите данные </h2>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" class="form form_container__forma">
<div class="form__inp-container">
<input name="chel_code" id="chel_code" type="text" class="forma__input" title="chel_code" required value="<?php echo $_COOKIE["chel_code"];?>">
</div>
<!-- rc -->
<!-- проверка google recaptcha 3 -->
<div class="forma__inp_hidden-container">
<input name="g-recaptcha-response" id="g-recaptcha-response" type="hidden" class="forma__input forma__input_hidden" title="g-recaptcha-response">
</div>
<!-- rc -->
<div class="form__inp-container">
<input name="form_name" id="name" type="text" class="forma__input" title="имя" tabindex="1" autofocus="autofocus" required placeholder="Имя:">
</div>
<div class="form__inp-container">
<input name="form_surname" id="surname" type="text" class="forma__input" title="фамилия" tabindex="2" required placeholder="Фамилия:">
</div>
<div class="form__inp-container">
<input name="form_email" id="email" type="text" class="forma__input" tabindex="3" required placeholder="Электронная почта: ">
</div>
<div class="form__inp-container">
<input name="form_phone" id="phone" type="text" class="forma__input" tabindex="4" required placeholder="Номер телефона: ">
</div>
<div class="form__inp-container">
<input name="form_ok" type="submit" value="ok " id="form_ok" class="forma__submit">
</div>
</form>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
Sergey Bulgakov , This is all because you skip part of the work that is being done, and describe only what you think is happening. And the code does not do what you mean. what you actually write.
Well, roughly speaking, I go to the site, a cookie is generated for me. For example, its value is id_407-1640605007.
I check in the inspector (chrome dev tools, mozilla developer tools). There, (mozilla - developer tools - "storage" - view all cookies), the same cookie is shown.
I fill out the form.
Sending.
I look at the mail.Which is logical, you didn’t take it out of shape ...
A letter arrives. My data is all the same as in the form when filling out.
The meaning of cookies is quite different. At all.
I don't understand why.Because it is important to check the values before sending. That's what var_dump() is for;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question