Page 1 of 1

Improving Polls, replacing session to cookie

Posted: Thu Feb 25, 2010 12:08 pm
by Rkz
Hi,
Its time to improve our polls system.

So I guess everyting what we need is in Polls.module.php file.

Im not stong programmer of cmsms, but I think It would be much easier when we have the code.

Make them eat the cookie:  line 274:

Code: Select all

		if (session_id()=="") session_start();

		$q="INSERT INTO ".cms_db_prefix()."module_pollblocked (sessionid,votetime,pollid) VALUES (?,?,?)";
here we have to set cookie:
it could be sth like this:

Code: Select all

setcookie ($this->GetPollName($pollid), "", time() + 60*60*24*30); // cookie with pool name and time to live
also we have to change this function line 107:

Code: Select all

function UserAlreadyVoted($pollid) {
		$db=&$this->GetDb();
		$q="SELECT * FROM ".cms_db_prefix()."module_pollblocked WHERE pollid=? AND sessionid=?";
		$p=array($pollid,session_id());
		$result=$db->Execute($q,$p);
		if (!$result || $result->RecordCount()<1) {
			return false;
		} else {
			return true;
		}
	}
to this:

Code: Select all

	function UserAlreadyVoted($pollid) {
if (isset($_COOKIE['$this->GetPollName($pollid)'])
 {
return true;
} 
else {
	return false;
	}
Is it OK? Please let me know what do you think about that idea