• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
prevention of the same user to run the script twice [multithreading?]

Here is the problem.
We have a script which is being called within page in another server.

All the user's information will be passed to us as well [cookie, ip , ... ].

By sometimes they have several copies of our script on their page (by mistake), so when a user visits the page our script is being executed twice, which is not desired for us.

We want each user to have the ability of executing our script one and only one time.
In our script we have preventions for : cookie , IP / Time, for each user.
I mean we set a cookie on user's side and every time we check the existence of that cookie.
Also we save the IP/Time in DB and check it too.
in the cases when the script is being executed exactly at the same time none of them work.

Is it something related to multi-threading ?

Does it have anything with Apache "Thread Safety " ?

I was thinking of while the first request to save the info to DB is being executed, the second request for the script arrives and easily pass the DB checking because it's not still being inserted to DB !

Any idea will be helpful and I'll appreciate it.

I don't understand. Can you post a link to the Web site?

well, everything is authenticated and I can not provide you with the login info.
consider it as a sale/tracking system.
And the shopping website has a call to our script to notify us who has made a sale at the end of checkout process.
and by each call, we notice that which user has done what sale.
but sometimes the shopping website has 2 or many instance of our script, which cause inaccurate tracking in our end.

I hope I had made it more clear.

Sorry, still don't understand. How is this "script" included twice, and is it JavaScript, or PHP? Without knowing more about the script you're including, and how you're including it, it's virtually impossible to come up with a solution.

The tracking system is CI based application.
We have a script for tracking the sales which is being called by an image from the last page of the shopping website.

Shopping website - Last page
<img src='http://example.com/sales_tracking/index.php/sale/trackSale/' />

But it could happen for a shoping owner to have such a thing :
&lt;iframe src='http://example.com/sales_tracking/index.php/sale/trackSale/'&gt;&lt;/iframe>

and in this case our script will be called twice at the same time.
THe time difference is so small that can not be detected, or maybe that;s because of the threading issue I mentioned earlier...
I want to get some idea how to prevent the second call from within the same page.

There are probably several solutions available, but all the ones I can think of are not 100% effective. The only thing I can suggest is to rethink the way you're doing this, and code defensively against this problem.

Thanks But how do you want to defend against something like this ?
IP / Time / Cookie are not sufficient as it's happening at very same time. What else you think can be useful ?

By coding defensively against the problem, I mean design your code not to let it happen in the first place, rather than trying to reverse engineer the problem. As we cannot see your code it's hard to troubleshoot it.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.