Hi all,

Im editting a whois script so when it returns the details of the whois search it returns one positive answer if the "loggedin" cookie is found, and another positive answer if it is not, and a negative one if the domain is taken. The whois script works fine but checking for the cookie does not.

It goes like this:

1) home page
---> (submit whois form (form action is step 2))

2) home page whois form action

require_once("AjaxWhois.php");
$whois = new AjaxWhois();
$domainName = (isset($_POST)) ? $_POST : '';
$whois->processAjaxWhois();

3) required file within whois form action

//whois processing has already been done. 
//if domain is available....
if ($this->checkDomain($domain,$server,$findText))
{
//check for cookie
	if (isset($_COOKIE['loggedin']))
		{
//and echo 'logged in message'
   	   echo "domain available. You are logged in.";
		}
else 
		{
//else echo 'not logged in message'
			echo "domain available. You are not logged in.";
		}
}
//unless domain is not available, echo 'not available message'
   else {echo "Domain not available.";}
}

The script always returns the 'you are not logged in' message even through the cookie is definately written. any ideas why?

Dani AI

Generated

Quick practical checks for (and building on 's suggestions): if the browser shows the cookie but your whois code still takes the "not logged in" branch, the usual causes are not the isset logic itself but the request/cookie configuration — common culprits are path or domain mismatch (example.com vs www.example.com), the Secure flag being set while the request is HTTP, reading the cookie in the same request that sets it (cookies only populate $_COOKIE on the next request), or an AJAX request that isn't sending credentials.

Add a server-side snapshot first to see what the whois script actually receives. Put this near the top of the whois handler (before your logic) and check the server error log:

error_log('REQUEST COOKIES: '.var_export($_COOKIE, true));

Also inspect the cookie in the browser DevTools Application/Storage tab to confirm Domain, Path, Secure, and HttpOnly attributes.

When you set the cookie, make the scope explicit so it is available to /whois/ and subdomains. Example:

setcookie('loggedin', $username, time()+3600, '/', '.example.com', isset($_SERVER['HTTPS']), true);

Remember: if you call setcookie() and then immediately check $_COOKIE in the same request, it will not be there unless you manually set $_COOKIE['loggedin'] = $username or redirect the client to a new request:

header('Location: /whois/whois.php');
exit;

If you tried sessions, ensure session_start() is called at the very top of every file before any output.

Quick troubleshooting checklist: verify exact host used (www vs non-www), check cookie Path/Domain/Secure flags in DevTools, log $_COOKIE on the whois request, ensure AJAX calls use credentials (XHR.withCredentials or fetch credentials), and prefer a redirect after setcookie when you expect an immediate authenticated state.

Recommended Answers

All 4 Replies

try this:

//whois processing has already been done. 
//if domain is available....
if ($this->checkDomain($domain,$server,$findText))
{
//check for cookie
	if (isset($_COOKIE['loggedin']))
		{
//and echo 'logged in message'
   	   echo "domain available. You are logged in.";
		}
if (!isset($_COOKIE['loggedin']))
		{
//else echo 'not logged in message'
			echo "domain available. You are not logged in.";
		}
}
//unless domain is not available, echo 'not available message'
   else {echo "Domain not available.";}
}

notice your else part,which i have changed...

Still not working. comes up with the same result - go on the link below to see screenshot.

"not logged in" under the add to basket button is put there because of an isset statement checking for the cookie

"already logged in" is put there because of the same isset statement checking for the same cookie

hello...
1.once check your setCookie() function,whether it is properly or not..
2. echo your cookie like: echo $_COOKIE["something"];
check it will print or not...
3. i heard that some browsers does not support cookies..
4.try sessions instead of cookies...

I have tried all of those.

my cookie prints out because in the screen shot of the page it shows the username saved as the value of the cookie so it prints out and has been set properly.

im using firefox and cookies normally work

sessions dont work either although i only tried breifly :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.