Hi drooghen,
You can basically accomplish this by creating these files:
- index.html
- validate.php
- create_profile.php
index.html could be your main page; this is where you ask your visitor for the code. So your index.html should have a form that looks like this:
[code]
Enter Code:
[/code]
validate.php is where you validate the code provided by the user. If code is valid, users have to provide required information like name, email, etc…otherwise, redirect to the index.html or error page. validate.php should look like this:
[php]
session_start();
include(‘connect.php’); //your database connection
$code=$_POST[‘code’]; //fetch code provided by the user
//suppose content_codes is the name of your table
$result=mysql_query(“SELECT * FROM content_codes WHERE code=’$code’”);
if (mysql_num_rows($result) < 1){
//code is invalid…redirect to error or main page
}
else{
//display another form; let’s ask users to provide more info
echo ’
Congratulations guest, but before you can download the content please provide your info....
Name:
Email:
';
//lets assign the correct code provided by the users into a session variable so that users need not to reenter the code when registration completes..
$_SESSION['code'] = $code;
}
[/php]
Your create_profile.php is where you save the info provided by the user. This is also where download link becomes visible. create_profile.php should look like this:
[php]
session_start();
include(‘connect.php’); //your database connection
$name=$_POST[‘name’];
$email=$_POST[‘email’];
$code=$_SESSION[‘code’]; //fetch the code previously entered by the user
//let’s save the info provided by the user (suppose you have ‘profile’ table)
mysql_query(“INSERT INTO profile (name, email) VALUES (’$name’, ‘$email’)”) or die(mysql_error());
//now, let’s provide the download link. I assume you have column ‘file_URL’ in table ‘content_codes’.
$results=mysql_query(“SELECT file_URL from content_codes WHERE code=’$code’”) or die(mysql_error());
$row=mysql_fetch_assoc($results);
//echo the download link
echo ‘Download Here’;
[/php]
That’s it! Hope this helps.