Issue with $_COOKIE


Joined
Apr 29, 2021
Messages
4
Reaction score
0
Hello! I'm experiencing a new issue--when I use $_COOKIE["yandex_login"] (the cookie that the API sends to the site which contains the email), it won't work. The code below is supposed to check if the email address contains my domain. It should be reporting "Word Found".

PHP:
<?php
$word = "mail.(my domain)";
$mystring = $_COOKIE["yandex_login"];
if(strpos($mystring, $word) !== false){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}
?>

The cookie seems to be pushed from domain .yandex.com and the path /

How can I get the value of the cookie if $_COOKIE isn't working? Is there a problem with my code?
 
Ad

Advertisements

Joined
Nov 13, 2020
Messages
80
Reaction score
14
This line -> $mystring = $_COOKIE["yandex_login"]; is not correct and you don't set the set the $_COOKIE[] info. Use
Code:
setcookie($mystring, $word);
after line 2.

Code:
<?php

$word = "mail.(my domain)";
$mystring = "yandex_login";
setcookie($mystring, $word);

if(isset($_COOKIE[$mystring]) && ($_COOKIE[$mystring] == $word)){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}
?>
 
Last edited:
Joined
Apr 29, 2021
Messages
4
Reaction score
0
This line -> $mystring = $_COOKIE["yandex_login"]; is not correct and you don't set the set the $_COOKIE[] info. Use
Code:
setcookie($mystring, $word);
after line 2.

Code:
<?php

$word = "mail.(my domain)";
$mystring = "yandex_login";
setcookie($mystring, $word);

if(isset($_COOKIE[$mystring]) && ($_COOKIE[$mystring] == $word)){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}
?>
Thanks for the response! Now it's creating a cookie named yandex_login at mail.(my domain). I may have phrased it wrong, I'm sorry. Here's the cookies on the page...

Domain => Name => Value
mail.(my domain) => yandex_login => mail.(my domain) *The code provided made this!
yandex.com => yandex_login => [email protected](my domain) *This is what I want to get!

Sorry for the confusion!

EDIT--For clarification, I want the script should check if the cookie yandex_login (the cookie that was sent to my site from yandex.com) contains mail.(my domain).
 
Ad

Advertisements

Joined
Nov 13, 2020
Messages
80
Reaction score
14
I gave you this
Code:
if(isset($_COOKIE[$mystring]) && ($_COOKIE[$mystring] == $word)){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}
Can not you change it to this
Code:
if(isset($_COOKIE["yandex_login"]) && ($_COOKIE[$"yandex_login"] == "mail.(my domain)"){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}
?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top