Your best bet is to use multiple GET arrays and conditional statements, and “echo” the function if it meets both conditions.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function randomString() {
return rtrim(base64_encode(md5(microtime())),"=");
}
if (
isset($_GET['userid'])
&&
!empty($_GET['userid'])
&&
isset($_GET['transactionid'])
&&
!empty($_GET['transactionid'])
)
{
echo randomString();
}
else{
echo "One GET array is not set or is empty.";
}
Nota:
- If this code gives you a parse error, then you are using it with something else that is causing it.
- This code was pre-tested, as shown and with no parse errors.
Edit:, using OP’s code and adding an echo inside the function.
Just add the echo in the function:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
function randomString() {
echo "Your code is: ";
return rtrim(base64_encode(md5(microtime())),"=");
}
// echo isset($_GET['userid']) && !empty($_GET['userid']) && isset($_GET['transactionid']) && !empty($_GET['transactionid']) ? randomString() : "ERROR";
echo isset($_GET['userid']) && !empty($_GET['userid']) && isset($_GET['transactionid']) && !empty($_GET['transactionid']) ? randomString() : "ERROR";
?>
</body>
</html>
2
solved PHP Random String Generator based on GET values [closed]