Solved

How do I store random number

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php ssh2_scp_send 1 47
Amazon Redshift 2 25
Regex PHP lines with newlines not being matched - all other match fine 4 22
PHP get array item with custom id 4 21
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

911 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

17 Experts available now in Live!

Get 1:1 Help Now