Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2011
    Location
    England
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question Simple secret code validator

    Hi there,

    I was wondering if there is a simple way of checking a 'secret code' in PHP without connecting to a database.

    For example - a candy company may advertise to their customers 'enter the code on your candy package online to enter the competition' with the code being 4470 (for example). Is there a way that I could do this, but for only one code? I don't want this validator to validate multiple codes, I want it to just validate one individual code.

    Is there a way to do this? Preferably without a database connection, but if its required, that's okay.

    Thanks!

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts
    If I were doing it, I would use jquery to send form data to another php file with an ajax request where the code could just be set manually. It would then return 1 if it's a match or 0 if it's not.

    If you're interested in doing it this way, let me know and I'll post the ajax request for making it work.

    Like I said though, to do it this way you'll need to install the jquery framework.

  • #3
    New Coder
    Join Date
    Aug 2011
    Location
    England
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks for replying!
    To be honest I am not very good at jquery or ajax as I'm learning PHP at the moment.
    BUT I would love to see this ajax request for making it work!
    Thanks!

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,590
    Thanks
    0
    Thanked 644 Times in 634 Posts
    Quote Originally Posted by camzenxbt View Post
    I was wondering if there is a simple way of checking a 'secret code' in PHP without connecting to a database.

    For example - a candy company may advertise to their customers 'enter the code on your candy package online to enter the competition' with the code being 4470 (for example).
    It is extremely easy to do.

    The form just needs to contain something like this:

    <label id="cde">Coupon Code: </label><input type="text" id="cde" name="cde">

    and then the following in thePHP will check if the correct code was entered:

    Code:
    if ($_POST('cde') == '4470') {
    // code to accept the entry goes here
    }
    Last edited by felgall; 04-29-2013 at 08:39 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    camzenxbt (05-02-2013)

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    if its via PHP just set it in a variable

    PHP Code:
    <?PHP

    $secret 
    '4470';

    if (
    $_GET['code'] == $secret){
        echo 
    'match';
    }else{
        echo 
    'no match';
    }

    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    camzenxbt (05-02-2013)

  • #6
    New Coder
    Join Date
    Aug 2011
    Location
    England
    Posts
    23
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks a lot guys for these answers!!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •