Here's a snippet of my code:

<?
include("include/session.php");
//include("forum/global.php");

$con = mysql_connect($dbhost,$dbuser,$dbpass);

$time = time();
$date = date("Y-n-j H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$email = $_POST['email'];
$lastname = ucwords($_POST['lastname']);
$firstname = ucwords($_POST['firstname']);
$firstinitial = $firstname[0];
$username = $firstinitial."_".$lastname;
$pass = $_POST['password'];

// MYBB

function generate_salt()
{
    return random_str(8);
}

function salt_password($password, $salt)
{
    return md5(md5($salt).$password);
}

$md5pass = md5($pass);
$salt = generate_salt();
$salted_pass = salt_password($md5pass, $salt);

$loginkey = random_str(50);

I get this error:

Fatal error: Call to undefined function random_str() in /home/myusername/public_html/thefile.php on line 20

Line 20 is the return random_str() line.
Can someone help me solve my problem please?

Recommended Answers

All 2 Replies

If you check line 21 of the code you pasted above, there is a call to the function random_str(). Where did you define this function ? By defining, it means where is the implementation of the function ? eg

function random_str($iLength)
{
  // code for generating a string containing $iLength random characters 
  // return the generated string
}

So, define your function somewhere in that file or perhaps in the global.php (which is commented out ?!?) then your error should vanish

Meaning random_str() inside the method generate_salt() is not defined

just write

return random()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.