PHP setcookie issues


#1

Trying to move my development of a web app to c9, so far I’m liking it. That being said my current code doesn’t seem to be working in the workspace. I’ve been trying to track down the issue (php debugger does not want to work for me in both the standard apache or php with built in webserver)

It just doesn’t seem to allow me to set custom cookies… here’s the code.

private function createCookie($rem, $uid){
		$db = new database;
		$security = new security;
		$session = new session;
		$selector = $security->randByte(12);
		$token = $security->randByte(64);
	while($session->authExist($selector)){
		$selector = $security->randByte(12);
	}
	
	if($rem){
		$cookie_name = "natgfx";
		setcookie($cookie_name, $selector.$token, time()+31556926, "/", "natgfx.com");
		
		$date = new DateTime();
		$date->add(DateInterval::createFromDateString('31556926 seconds'));
		$date = date_format($date, 'Y-m-d H:i:s');
		$submit = array();
		$submit['id'] = "";
		$submit['selector'] = $selector;
		$submit['token'] = hash('sha256', $token);
		$submit['uid'] = $uid;
		$submit['expires'] = $date;
		
		$result = $db->newRow('auth_tokens', $submit);
		
		return $result;
	
	}
	else{
	 $cookie_name = "natgfx";
	 error_log("derp");
		setcookie($cookie_name, $selector.$token, time()+86400, "/", "natgfx.com");
		
		$date = new DateTime();
		$date->add(DateInterval::createFromDateString('86400 seconds'));
		$date = date_format($date, 'Y-m-d H:i:s');
		$submit = array();

		$submit['id'] = "";
		$submit['selector'] = $selector;
		$submit['token'] = hash('sha256', $token);
		$submit['uid'] = $uid;
		$submit['expires'] = $date;
		
		$result = $db->newRow('auth_tokens', $submit);
		error_log("this is result ".$result);
		return $result;
	}
	
} 

The function executes and follows the correct logic through to success, updates the db and all that but never actually sets the cookie…


#2

I’m an idiot

setcookie($cookie_name, $selector.$token, time()+31556926, "/", "natgfx.com");

natgfx.com needed to be set to c9users.io