Solved

How do I store random number

Posted on 2011-03-16
2
342 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

830 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