Solved

How do I store random number

Posted on 2011-03-16
2
343 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
[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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.

737 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