Reputation: 10117
I have an image uploading script in which i use the following setup to assign names to uploaded images;
$saltdate = date( 'U' );
$saltuser = $_SERVER[REMOTE_ADDR];
$saltname = md5($saltdate.$saltuser);
// Recieve, Process, Save uploaded image
// Update database with image name
The problem that i encounter is that after processing/saving the image, when its time to add this file name to the database, the value of $saltdate
seems to have changed and i will get a file name in the database that doesnt exist.
EDIT
The value has changed in that the time increases from when i name the file to when i store the name in the DB.
How can i make sure that the value doesn't change once i establish it?
Upvotes: 0
Views: 146
Reputation: 96159
This is the kind of error where a debugger comes in really handy. You can set a breakpoint in your code and then execute it step by step and inspect the state of variables et al.
You can use XDebug as the server-side php module and e.g. netbeans as a frontend/ide.
There's a short introduction for this combination at http://netbeans.org/kb/docs/php/debugging.html
Upvotes: 1
Reputation: 382686
Since you are using the md5()
function, make sure that you are doing the same thing while retrieving the record back. Notice that you are using a date in your salt, make sure that things match up.
An easy way is to use microtime
function instead.
Upvotes: 1