Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Web Script Needed to Generate Registration Code

Posted on 2008-10-19
2
Medium Priority
?
304 Views
Last Modified: 2013-12-25
I need a PHP or CGI script that will create a page and a random registration code for a software program that I had written. The code is 16 digits and is made up of letters and numbers. The first 4 and last 4 digits are to be pulled at random from a file named rannum.txt, the 8 digits in the middle should be random, it doesn't matter what they are as long as they are a random number or letter.

The rannum.txt file is in the following format&

AXDF
A2LR
R889
Z0L3

I am sending the person to the following URL, this is an example

www.myurl.com/code.php?address@email.com

The page that is generated should look like this, I'll edit the text to match what I need it to say later. The main part is that their email address should be on the page as well as the 16 digit number

-----

Thank You

Please use the following to register your program

address@email.com

[16 digit random code here]

-----

I would also like the URL to not display the ? and the email address if at all possible once the page loads. If they try to access the page directly without using the ?address@email.com, I would like to have the script leave them with the following message. I'll edit the message later to suit my needs.

The code did not generate. Please contact me for additional help with this
0
Comment
Question by:timshank
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
wildzero earned 2000 total points
ID: 22756242
Here you go
www.myurl.com/code.php?e=address@email.com
Notice the extra bit there, e=

rannum.txt goes in the same folder as code.php

It uses sessions to keep track of generated code and email when removing the email from the url. This means for as long as the session is open it will continue to display there code and email when they return.

To remove this simply change the bottom of the file from
      <?php }
?>
to
      <?php }
session_destroy();
?>

<?php
	session_start();
	
	If (isset($_GET['e'])) {
		//Load in the random text file to an array
		$file = file('rannum.txt');
		
		$code = trim($file[rand(1,count($file))-1]);
		$code.= rand(1000,9999);
		$code.= trim($file[rand(1,count($file))-1]);
		
		//Set the code and email to session 
		$_SESSION['code'] = $code;
		$_SESSION['email'] = str_replace(array('<', '>', '/', '\/', '%'), '', $_GET['e']);		
		header("Location: /code.php");
		exit;
	}
	
	
	If (isset($_SESSION['code'], $_SESSION['email'])) {
	?>
		
		<p>Thank You</p>
 
		<p>Please use the following to register your program</p>
 
		<p><?php echo $_SESSION['email']; ?></p>
 
		<p><?php echo $_SESSION['code']; ?></p>
 
	<?php
	} else {
	?>
	
	<p>The code did not generate. Please contact me for additional help with this</p>
	
	<?php }
?>

Open in new window

0
 

Author Closing Comment

by:timshank
ID: 31507699
Excellent Job. Thank You!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question