md5($_POST['username'] + microtime() ) says it encountered a non-numeric value since new php version
I reinstalled WAMP and now I have PHP version 7.1.9 (before this I had 7.0 x).
A part of the code doesn’t work anymore without warning/notice reports.
- Warning: A non-numeric value encountered in
And:
- Notice: A non well formed numeric value encountered in
The script with the error contains the following code:
<?php $_POST['username'] = 'yourname';
$code = md5($_POST['username'] + microtime() ) ;
var_dump($code); ?>
I believe that my problem arises as a result of upgrading my PHP interpreter.
I had better results with setting microtime to microtime(true)
.
The errors are even not there when I set $_POST['username']
to a number.
But like I said: I want to know what causes it and how to solve it.
I also read through the php migrating docs to find anything about microtime or variables regarding md5 maybe, but nothing.
Could it be the settings are different in Wamp or possible it is a bug in php or so?
php microtime
add a comment |
I reinstalled WAMP and now I have PHP version 7.1.9 (before this I had 7.0 x).
A part of the code doesn’t work anymore without warning/notice reports.
- Warning: A non-numeric value encountered in
And:
- Notice: A non well formed numeric value encountered in
The script with the error contains the following code:
<?php $_POST['username'] = 'yourname';
$code = md5($_POST['username'] + microtime() ) ;
var_dump($code); ?>
I believe that my problem arises as a result of upgrading my PHP interpreter.
I had better results with setting microtime to microtime(true)
.
The errors are even not there when I set $_POST['username']
to a number.
But like I said: I want to know what causes it and how to solve it.
I also read through the php migrating docs to find anything about microtime or variables regarding md5 maybe, but nothing.
Could it be the settings are different in Wamp or possible it is a bug in php or so?
php microtime
2
try using the period.
to concatenate the string and microtime rather than the plus+
– RamRaider
Sep 30 '17 at 11:52
Thank you RamRaider. This works for me. But I'm still curious why the + worked before and not in this situation?
– WesleyJ.
Sep 30 '17 at 11:56
Yes and I upvoted you
– WesleyJ.
Jan 3 at 9:54
add a comment |
I reinstalled WAMP and now I have PHP version 7.1.9 (before this I had 7.0 x).
A part of the code doesn’t work anymore without warning/notice reports.
- Warning: A non-numeric value encountered in
And:
- Notice: A non well formed numeric value encountered in
The script with the error contains the following code:
<?php $_POST['username'] = 'yourname';
$code = md5($_POST['username'] + microtime() ) ;
var_dump($code); ?>
I believe that my problem arises as a result of upgrading my PHP interpreter.
I had better results with setting microtime to microtime(true)
.
The errors are even not there when I set $_POST['username']
to a number.
But like I said: I want to know what causes it and how to solve it.
I also read through the php migrating docs to find anything about microtime or variables regarding md5 maybe, but nothing.
Could it be the settings are different in Wamp or possible it is a bug in php or so?
php microtime
I reinstalled WAMP and now I have PHP version 7.1.9 (before this I had 7.0 x).
A part of the code doesn’t work anymore without warning/notice reports.
- Warning: A non-numeric value encountered in
And:
- Notice: A non well formed numeric value encountered in
The script with the error contains the following code:
<?php $_POST['username'] = 'yourname';
$code = md5($_POST['username'] + microtime() ) ;
var_dump($code); ?>
I believe that my problem arises as a result of upgrading my PHP interpreter.
I had better results with setting microtime to microtime(true)
.
The errors are even not there when I set $_POST['username']
to a number.
But like I said: I want to know what causes it and how to solve it.
I also read through the php migrating docs to find anything about microtime or variables regarding md5 maybe, but nothing.
Could it be the settings are different in Wamp or possible it is a bug in php or so?
php microtime
php microtime
edited Dec 30 '18 at 17:16
yivi
4,92972654
4,92972654
asked Sep 30 '17 at 11:49
WesleyJ.WesleyJ.
1611
1611
2
try using the period.
to concatenate the string and microtime rather than the plus+
– RamRaider
Sep 30 '17 at 11:52
Thank you RamRaider. This works for me. But I'm still curious why the + worked before and not in this situation?
– WesleyJ.
Sep 30 '17 at 11:56
Yes and I upvoted you
– WesleyJ.
Jan 3 at 9:54
add a comment |
2
try using the period.
to concatenate the string and microtime rather than the plus+
– RamRaider
Sep 30 '17 at 11:52
Thank you RamRaider. This works for me. But I'm still curious why the + worked before and not in this situation?
– WesleyJ.
Sep 30 '17 at 11:56
Yes and I upvoted you
– WesleyJ.
Jan 3 at 9:54
2
2
try using the period
.
to concatenate the string and microtime rather than the plus +
– RamRaider
Sep 30 '17 at 11:52
try using the period
.
to concatenate the string and microtime rather than the plus +
– RamRaider
Sep 30 '17 at 11:52
Thank you RamRaider. This works for me. But I'm still curious why the + worked before and not in this situation?
– WesleyJ.
Sep 30 '17 at 11:56
Thank you RamRaider. This works for me. But I'm still curious why the + worked before and not in this situation?
– WesleyJ.
Sep 30 '17 at 11:56
Yes and I upvoted you
– WesleyJ.
Jan 3 at 9:54
Yes and I upvoted you
– WesleyJ.
Jan 3 at 9:54
add a comment |
2 Answers
2
active
oldest
votes
You should write line like :
<?php
$_POST['username'] = 'yourname';
$code = md5( $_POST['username'] . microtime() ) ;
var_dump( $code ); ?>
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
add a comment |
You get this error because starting with PHP7 the interpreter is a little less lax when doing type conversions.
Going by parts, you are trying to add (as in: using the addition operator, ++
) two values and whatever you have in $_POST['username']
is certainly not a valid number; and the return of microtime()
, by default, is not a valid number either.
Before PHP 7.1, this would work silently, and the intepreter would perform a silent type cast behind the scenes, never complaining. But on PHP >= 7.1, you need to be a bit more careful with types.
The suggested workaround of using the concatenation operator (.
) works because of the result of microtime()
and the contents of $_POST['username']
are both strings, and md5()
expects a string as a parameter anyway.
$code = md5( $_POST['username'] . microtime() ) ;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46502420%2fmd5-postusername-microtime-says-it-encountered-a-non-numeric-value-s%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should write line like :
<?php
$_POST['username'] = 'yourname';
$code = md5( $_POST['username'] . microtime() ) ;
var_dump( $code ); ?>
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
add a comment |
You should write line like :
<?php
$_POST['username'] = 'yourname';
$code = md5( $_POST['username'] . microtime() ) ;
var_dump( $code ); ?>
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
add a comment |
You should write line like :
<?php
$_POST['username'] = 'yourname';
$code = md5( $_POST['username'] . microtime() ) ;
var_dump( $code ); ?>
You should write line like :
<?php
$_POST['username'] = 'yourname';
$code = md5( $_POST['username'] . microtime() ) ;
var_dump( $code ); ?>
answered Sep 30 '17 at 11:55
Punit PatelPunit Patel
1326
1326
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
add a comment |
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
Yes Punit I agree fully with you that it is clearer to break after every sentence. But to explain a bit more about what happened while I made the post: I pressed the curly brackets icon but I had to press it three times and had to copy paste each sentence 3 times. This is the first time this happened to me, as far as I remember.
– WesleyJ.
Sep 30 '17 at 14:12
add a comment |
You get this error because starting with PHP7 the interpreter is a little less lax when doing type conversions.
Going by parts, you are trying to add (as in: using the addition operator, ++
) two values and whatever you have in $_POST['username']
is certainly not a valid number; and the return of microtime()
, by default, is not a valid number either.
Before PHP 7.1, this would work silently, and the intepreter would perform a silent type cast behind the scenes, never complaining. But on PHP >= 7.1, you need to be a bit more careful with types.
The suggested workaround of using the concatenation operator (.
) works because of the result of microtime()
and the contents of $_POST['username']
are both strings, and md5()
expects a string as a parameter anyway.
$code = md5( $_POST['username'] . microtime() ) ;
add a comment |
You get this error because starting with PHP7 the interpreter is a little less lax when doing type conversions.
Going by parts, you are trying to add (as in: using the addition operator, ++
) two values and whatever you have in $_POST['username']
is certainly not a valid number; and the return of microtime()
, by default, is not a valid number either.
Before PHP 7.1, this would work silently, and the intepreter would perform a silent type cast behind the scenes, never complaining. But on PHP >= 7.1, you need to be a bit more careful with types.
The suggested workaround of using the concatenation operator (.
) works because of the result of microtime()
and the contents of $_POST['username']
are both strings, and md5()
expects a string as a parameter anyway.
$code = md5( $_POST['username'] . microtime() ) ;
add a comment |
You get this error because starting with PHP7 the interpreter is a little less lax when doing type conversions.
Going by parts, you are trying to add (as in: using the addition operator, ++
) two values and whatever you have in $_POST['username']
is certainly not a valid number; and the return of microtime()
, by default, is not a valid number either.
Before PHP 7.1, this would work silently, and the intepreter would perform a silent type cast behind the scenes, never complaining. But on PHP >= 7.1, you need to be a bit more careful with types.
The suggested workaround of using the concatenation operator (.
) works because of the result of microtime()
and the contents of $_POST['username']
are both strings, and md5()
expects a string as a parameter anyway.
$code = md5( $_POST['username'] . microtime() ) ;
You get this error because starting with PHP7 the interpreter is a little less lax when doing type conversions.
Going by parts, you are trying to add (as in: using the addition operator, ++
) two values and whatever you have in $_POST['username']
is certainly not a valid number; and the return of microtime()
, by default, is not a valid number either.
Before PHP 7.1, this would work silently, and the intepreter would perform a silent type cast behind the scenes, never complaining. But on PHP >= 7.1, you need to be a bit more careful with types.
The suggested workaround of using the concatenation operator (.
) works because of the result of microtime()
and the contents of $_POST['username']
are both strings, and md5()
expects a string as a parameter anyway.
$code = md5( $_POST['username'] . microtime() ) ;
edited Jan 3 at 9:48
answered Dec 30 '18 at 17:14
yiviyivi
4,92972654
4,92972654
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46502420%2fmd5-postusername-microtime-says-it-encountered-a-non-numeric-value-s%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
try using the period
.
to concatenate the string and microtime rather than the plus+
– RamRaider
Sep 30 '17 at 11:52
Thank you RamRaider. This works for me. But I'm still curious why the + worked before and not in this situation?
– WesleyJ.
Sep 30 '17 at 11:56
Yes and I upvoted you
– WesleyJ.
Jan 3 at 9:54