Help With Captcha System (Same Random Number on 2 Pages?)

I have a website that’s been having some spam problems, and so I created a system that makes a user do a captcha every week before they can access the website. None of it is super advanced, so just for reference, here is how it basically works:

[php]

<?php if($_COOKIE['beenhere']) { } else { header('Location: [Page with captcha]'); } ?>

[/php]
This first section of PHP is on the page of the website that gets the spam problem. It checks to see if they have the cookie that lets them bypass the captcha. If they don’t, they are redirected to the page with the captcha on it. Once the captcha is submitted, they are sent to the page that verifies that the captcha is correct:

[php]

<?php [Irrelevant stuff from the captcha...The part below gets executed if the captcha is correct] ?> [/php]

If it is correct, they are redirected to a page with that does this:

[php]<?php
$tk=$_GET[“tk”];
if ($tk==“123849084098430928004983029”) setcookie(“beenhere”,‘1’, time()+3600*168);
?>

[/php]

This page sets the cookie and redirects them back to the homepage.

So the problem here is that just by going to the continue.php page, you would be able to get the cookie that allows you to bypass the captcha. So that’s why I temporarily added the part where you need that long number to be in the URL on the continue.php page in order for it to set the cookie.

What I’m wondering is if there is a way to make that long number be a different thing every time? Remember that the same random number would have to be on two different pages (is has to be like that…the captcha system was giving me errors when I tried to put the part where it created the cookie on the page that verifies that captcha). If that’s not possible, are there any other suggestions for what to do?

Thanks in advance!

Does anybody have any suggestions?

Sure, just use the login page to set this crazy number inside a SESSION variable.
When the session is gone, the crazy number is gone.
Anyone going to the page directly will not be logged in, hence no session, no crazy number…
That way, you do not pass the crazy number in any viewable way such as a webpage…
(A webpage can be captured, a session variable can not as it is only SERVER-SIDE!)

Hope that helps…

Yes, thank you! Isn’t it funny how the answer is always so obvious? :slight_smile:

Yes! I totally agree. I was just helping someone else with passing a secret webpage name for hiding it on the address bar in the same manor which I came across your project. Nice to help two people in the same manor!

If you have any questions about session variables, ask away… Or let us know if it is solved and we will mark it so. good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service