Jump to content

$_COOKIE does not read existing cookie


kortoom

Recommended Posts

When a user subscribes to my site I create a random identifier with md5.  I put this identifier in an email to the user and in a cookie on their machine.  When they get the email and click on the link, the identifier (and their email address) is in the URL.  They land on the page whose code is below. This code gets the information from the URL just fine. 

 

But I can not get $_COOKIE to work at all, even though the cookie is right there, with the identifier in it.  I am missing something that enables the landing page to read a cookie that is already there in the browser's cookie directory. 

 

I truly appreciate your help with what must be a simple error!!!

 

<?php

 

//first get the email address from the email url -- this works

 

$fans_email=$_GET['email'];

 

//next get the identifier from the email url -- this works

 

$fans_id=trim($_GET['id']);

 

//next get the identifier from the cookie -- this fails

 

$cookie_id=trim($_COOKIE['subttih']);

 

// if the ids match, confirm and continue, if they don't, ask user to retry -- this always fails since there's no cookie value

 

if ($fans_id=$cookie_id) {

Header("Location:http://www.tothinkishuman.com/confirm-ok.php?email=$fans_email");

} else {

Header("Location:http://www.tothinkishuman.com/confirm-ko.php");

}

?>

 

 

Link to comment
Share on other sites

So, what values do you use in setcookie() for the PATH and DOMAIN parameters and what if anything is different between the PATH and DOMAIN of the page where the cookie is set and the code you posted?

 

You should actually store the unique id on the server and associate it with the email address because as soon as someone looks at the cookie and the link they will notice that they can create an account on your site by simply putting the same value into their cookie and into the link when their bot script visits your site.

Link to comment
Share on other sites

THANK YOU BOTH!

 

RusselReal & PFMaBiSmAd, avoiding the cookie altogether and using the db was the solution I implemented

 

PFMaBiSmAd, the PATH and DOMAIN parameters ought to have been the same, but since I don't actually know that they were, this insight would probably have led to a solution of the cookie issue.

 

BLESSINGS!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.