Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

How do I store random number

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
petersego
Asked:
petersego
1 Solution
 
Beverley PortlockCommented:
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
 
petersegoAuthor Commented:
Thanks, thats just perfect.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now