开发者

Value of variable changing before function is finished running

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 i开发者_高级运维mage 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?


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


Set it as a constant with define


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜