Promotional Code - PHP Coding

I am a beginner when it comes to php so need help. I am using php code for a promotional code box to redirect customers to a new URL, so they input the code in a promo box on my home page which then redirects them to the special URL page with special offers. I now need to provide a large number of codes for a promotion we are going to run, all the codes need to be unique so I was wondering if there was a way to develop a 6 digit code where the first 4 digits only are recognised by the php script (this will be the same on all codes), and the last 2 digits are ignored when the customer enters their unique code in the box?? So we give the customer a 6 digit code but the script just uses the first 4 digits and ignores the last 2.
The code I am using is:

[php]<?php
$errmsg = “”;
if (empty($_POST[‘pcode’])) {
$errmsg = ‘Enter promotional code’;
include ‘promoform.php’;

} else {
switch($_POST[‘pcode’]) {
case “code123”:
$redirectpage = ‘http://www.website.com’;
break;
case “code456”:
$redirectpage = ‘http://www.website.com’;
break;
}
header(“Location: $redirectpage”);
}
?>

[/php]Any suggestions are welcome, thanks.

First, you need to be storing the codes/ urls in a database, xml, or other flat file for look up.

Then it is just a matter of using substr to grab the first four digits, comparing and redirecting.

Great! Being new to php where would the substr code go?

Rather than tell you, I’ll just some pushing.

In order to route the request, you stated you needed to know the first four digits of the code. So, in order to route the request you need those four digits. Where would you put a function to get those digits at?

Write on a piece of paper the steps needed for the flow of the program.

Hi sorry, I really don’t have a clue when it comes to php. Not really sure what where to start with your suggestion.

It actually has nothing to do with PHP, it has to do with logic and what processes get accessed in the flow of the program.

If you receive a code, how soon do you act on it?

Sponsor our Newsletter | Privacy Policy | Terms of Service