Solved

How do I store random number

Posted on 2011-03-16
2
339 Views
Last Modified: 2012-05-11
My PHP-knowledge is limited, so maybe this is a very simple question.
Is there a way to store a random number on the server for a limited time.
The scenario is this.
I have a flashmovie, that is communicating with various php-scripts.
As a start the flashmovie validates username and password through checklogin.php.
As part of the validation-proces I want to send a random number or security-word back to the flash-movie.
When the flash-movie then communicates with another php-scripts - like createxml.php, I want it to send the random-number as a securitymeasure before the actual php-script executes.
if ($flash-number==$server-number)
But that takes that the random number is stored either in an included file or in some other manner.
0
Comment
Question by:petersego
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 35148022
You could try storing it in the session, but since the flash runs on the client PC it probably will not have access to the session. You could try passing a URL parameter around but it would have to be encoded in some way.

The simplest way is to assemble information like the remote IP address and today's date and MD5 it together with a random number and then pass the random number and the MD5 as URL parameters. The receiving scripts can then reconstruct the MD5 themselves and compare it with the passed version. A match indicates an authorised script. SO you would do something like this (UNTESTED)

$ip = $_SERVER['REMOTE_ADDR'];
$today = date("Y-m-d");
$number = mt_rand( 1, 2000000000 );
$md5 = md5( $ip . $today . $number );

.....

header( "Location: http://myserver.com/myscript.php?number=$number&key=$md5");


and in the receiving script

$ip = $_SERVER['REMOTE_ADDR'];
$today = date("Y-m-d");
$number = $_GET['number'];
$md5 = md5( $ip . $today . $number );

if ( $md5 == $_GET['key'] )
   // valid
else
   // invalid


This method is temporary because the key contains a date and it is locked to one IP address. Because it is in the URL it gets lost when the browser is closed and bookmarking it only works for one day. Because it gets passed around you don't need to worry about whether it is stored on the server or client.

A more robust version would be to use full blown encryption but MD5 is probably available in Flash but I don't know about encryption functions being available in flash.

0
 

Author Closing Comment

by:petersego
ID: 35149668
Thanks, thats just perfect.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now