Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Server-side Scripting _ Give a player points 1 time.

Posted by: FrostTaco May 14 2016, 11:09 PM

Hi guys, today I was coding away with everything working until I noticed a problem. Players can refresh a link I give them to give them extra points. Basically, I have gleam.io giveaways, and one of the ways to enter is to use a link to my website, which allows you to gain 1, and only 1 point. However, if the user saves the link, they can just refresh the page and do anything and keep earning points. Points are stored in a file: useridcustom.json Of course, userid is replaced with the users id. How can I make a player use the link only once? Link example: corndog.corticalcafe.com/index.php?gid=1&pts=1 gid is the giveaway id, and pts of course is the points the player earns(The player cannot see the link until its been used so they cant change pts=1). Does anyone know of an easy way to allow players to use it once?

Note: It would be best if I don't have to store it in a file, as their will be a lot of giveaways, meaning the file would get real messy quickly.

Posted by: CharlesEF May 15 2016, 04:15 AM

If I understand the problem correctly the only sure way of doing this is with a database. How/when/where is the json created? Is it a file or just a variable, PHP/Javascript?

Posted by: FrostTaco May 15 2016, 09:01 AM

QUOTE(CharlesEF @ May 15 2016, 05:15 AM) *

If I understand the problem correctly the only sure way of doing this is with a database. How/when/where is the json created? Is it a file or just a variable, PHP/Javascript?

The json file is created when a player logs in for their first time in the cache folder. The file then can be edited so the user can change some information on their account. This file also stores the players points. I used php to make the file.

Posted by: CharlesEF May 15 2016, 06:43 PM

QUOTE(FrostTaco @ May 15 2016, 09:01 AM) *
The json file is created when a player logs in for their first time in the cache folder. The file then can be edited so the user can change some information on their account. This file also stores the players points. I used php to make the file.

So each player has their own json file, correct? How is the link created? Do you use PHP to parse the json file and create the link? If yes then you could remove the data for the points after they are used and re-write the json file.

Posted by: FrostTaco May 16 2016, 03:51 PM

QUOTE(CharlesEF @ May 15 2016, 07:43 PM) *

QUOTE(FrostTaco @ May 15 2016, 09:01 AM) *
The json file is created when a player logs in for their first time in the cache folder. The file then can be edited so the user can change some information on their account. This file also stores the players points. I used php to make the file.

So each player has their own json file, correct? How is the link created? Do you use PHP to parse the json file and create the link? If yes then you could remove the data for the points after they are used and re-write the json file.


I don't really understand, and yes each player has their on json file
Not sure if this is what you said, but here is what I think will work: I generate a file with a list of different codes. In the url, I change gid to id=code when the player uses that link, it removes the code from the file. Going to try this smile.gif

EDIT: Is their any quick way I can just easily generate lots of 7 or 8 digit codes(letters and #s)?

Posted by: CharlesEF May 17 2016, 09:26 AM

Yes, that is the idea. Each player will have their own points file. When the page is served up PHP can parse the file and create then echo the link. When the player clicks on the link PHP should remove that entry from the file. This way, if the user reloads the page the link will not be created again.

I still think it would be better if you used a database for this.

Posted by: FrostTaco May 20 2016, 10:04 PM

QUOTE(CharlesEF @ May 17 2016, 10:26 AM) *

Yes, that is the idea. Each player will have their own points file. When the page is served up PHP can parse the file and create then echo the link. When the player clicks on the link PHP should remove that entry from the file. This way, if the user reloads the page the link will not be created again.

I still think it would be better if you used a database for this.

But how does the player actually get to that page in the first place?

Posted by: CharlesEF May 21 2016, 12:57 AM

QUOTE(FrostTaco @ May 20 2016, 10:04 PM) *
But how does the player actually get to that page in the first place?

Well, how do you currently create the link? It is at this point that I suggest you incorporate the new program logic. You have never posted your code, only a description of the problem. So, I can't tell you exactly how to do it.

Posted by: FrostTaco May 21 2016, 08:50 AM

QUOTE(CharlesEF @ May 21 2016, 01:57 AM) *

QUOTE(FrostTaco @ May 20 2016, 10:04 PM) *
But how does the player actually get to that page in the first place?

Well, how do you currently create the link? It is at this point that I suggest you incorporate the new program logic. You have never posted your code, only a description of the problem. So, I can't tell you exactly how to do it.


That's the problem, I don't have that code! I was thinking maybe the webpage should pick a link when its loaded for the first time with a special id(http://corndog.corticalcafe.com/greward.php?rid=id). Now it saves that code for just that user and just for the id(rid). If another person uses that id though, they get a completely different code. However, if the first person uses a different id, they then get a different code. Do you think this would work? I'm just not sure now tongue.gif I'm pretty sure I would have to make a new file for every person called something like usedids-playerid.json

Posted by: FrostTaco May 21 2016, 02:04 PM

QUOTE(FrostTaco @ May 21 2016, 09:50 AM) *

QUOTE(CharlesEF @ May 21 2016, 01:57 AM) *

QUOTE(FrostTaco @ May 20 2016, 10:04 PM) *
But how does the player actually get to that page in the first place?

Well, how do you currently create the link? It is at this point that I suggest you incorporate the new program logic. You have never posted your code, only a description of the problem. So, I can't tell you exactly how to do it.


That's the problem, I don't have that code! I was thinking maybe the webpage should pick a link when its loaded for the first time with a special id(http://corndog.corticalcafe.com/greward.php?rid=id). Now it saves that code for just that user and just for the id(rid). If another person uses that id though, they get a completely different code. However, if the first person uses a different id, they then get a different code. Do you think this would work? I'm just not sure now tongue.gif I'm pretty sure I would have to make a new file for every person called something like usedids-playerid.json


Just noticed a much easier way todo it, thanks anyways smile.gif

Posted by: FrostTaco May 21 2016, 06:34 PM

So sorry, but I was wondering, how do I refresh the page on button click, but add the parameter rep=1 while keeping the other parameters in the url?

Posted by: CharlesEF May 23 2016, 02:15 PM

QUOTE(FrostTaco @ May 21 2016, 06:34 PM) *

So sorry, but I was wondering, how do I refresh the page on button click, but add the parameter rep=1 while keeping the other parameters in the url?

Since you say a button click then you would need to use javascript. On button click you would need to read the current HREF (assign to a variable) then add whatever query string you want to that variable then use the new link/variable to load the page.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)