appleguy6142
03-16-2009, 03:23 PM
Hey Everyone!
I want to make a points system so that everytime someone visits a page they get 10 points or so, then when they have got about 100 points they can go onto another page. How do i do that?
Josh R
PS: if there is any widgets that do that, please let me know!
rangana
03-17-2009, 06:36 AM
If you're using this for a large project, then you need to indulge yourself into server-side.
The process...
You get the user's IP, and find match of it in your database. If a match exists, then check if the points earned matches your "maxPoints" from your example, it is 100, otherwise iincrement the point value of that IP.
Otherwise, store the IP to your database.
If this isn't for a large-scale project, and you would rather find a JS solution, you might find this code useful:
<script type="text/javascript">
window.addEventListener?window.addEventListener('load',function () {
ray.checkCookie({
maxPoint:100, // The max points you wish to set
url:'http://www.google.com', // If they reach the max point, they'll be redirect to this URL
cookieName:'points', // Name of your cookie
cookieExpire:365 // Means ~ 1 year: 365 days
});
},false):
window.attachEvent('onload',function () {
ray.checkCookie({
maxPoint:100, // The max points you wish to set
url:'http://www.google.com', // If they reach the max point, they'll be redirect to this URL
cookieName:'points', // Name of your cookie
cookieExpire:365 // Means ~ 1 year: 365 days
});
}); // FF : IE
var ray = {
maxPoint:100, // Default max point
url:'', // If they reach the max point, they'll be redirect to this URL
points:0, // Store cookie
cookieName:'points', // Default cookie name
cookieExpire:365, // Default expire days
getCookie:function (c_name) {
if (document.cookie.length>0) {
var c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1) {
c_start=c_start + c_name.length+1;
var c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1)
c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
},
setCookie:function (c_name,value,expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
},
checkCookie:function (obj) {
this.maxPoint = obj.maxPoint?obj.maxPoint:this.maxPoint;
this.url = obj.url?obj.url:this.url;
this.cookieName = obj.cookieName?obj.cookieName:this.cookieName;
this.cookieExpire = obj.cookieExpire?obj.cookieExpire:this.cookieExpire;
this.points=this.getCookie(this.cookieName);
if (this.points!=null && this.points!="" && (Number(this.points) >= this.maxPoint))
location.href=this.url;
if (this.points!=null && this.points!="")
this.setCookie(this.cookieName,Number(this.points)+10,this.cookieExpire);
else {
this.points = 10;
if (this.points!=null && this.points!="")
this.setCookie(this.cookieName,this.points,this.cookieExpire);
}
}
}
</script>
Hope that helps.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.