Jump to content

Fatal Error: cannot redeclare


Bottyz

Recommended Posts

hi all,

 

 

I found an error whilst testing an activate users script i've been testing and debugging, but i can't find a way around this bug?

 

Basically, it only happens when there is more than one user to activate in a list. And on the second, thrid, fourth, etc... in the loop the function to generate a random password cannot be redeclared?

 

the problematic section fo the code is below:

 

// connect to db
   
foreach($_POST['userID'] as $uID){      
	$productaccess1 = isset($_POST[$uID.'_PA1']) ? '1' : '0';
	$productaccess2 = isset($_POST[$uID.'_PA2']) ? '1' : '0';
	$productaccess3= isset($_POST[$uID.'_PA3']) ? '1' : '0';
	$productaccess4 = isset($_POST[$uID.'_PA4']) ? '1' : '0';
	$deleterecord = isset($_POST[$uID.'_DEL']) ? '1' : '0';

	$productaccess1a = "No";
	$productaccess2a = "No";
	$productaccess3a = "No";
	$productaccess4a = "No";

	//Generate random password
	function random_password($password) {
		$vowels = 'aeuy';
		$consonants = 'bdghjmnpqrstvz';
		$length = 8;
		$strength = 4;
		if ($strength & 4) {
			$vowels .= "AEIOU";
			$consonants .= 'BDGHJLMNPQRSTVWXYZ23456789';
		}
		if ($strength &  {
			$consonants .= '@#$%';
		}

		$password = '';
		$alt = time() % 2;

		for ($i = 0; $i < $length; $i++) {
			if ($alt == 1) {
				$password .= $consonants[(rand() % strlen($consonants))];
				$alt = 0;
			} else {
				$password .= $vowels[(rand() % strlen($vowels))];
				$alt = 1;
			}
		}
		return $password;
	}

	$theirpassword = random_password($password);

	// encrypts the randomly generated 8 digit password into 32 digit hash
	$their_password = md5($theirpassword);

 

Is it something that cannot be done in a loop?

 

thanks in advance

Link to comment
Share on other sites

code should be like this

 

<?php



foreach($_POST['userID'] as $uID) {

    $productaccess1 = isset($_POST[$uID.'_PA1']) ? '1' : '0';


    $productaccess2 = isset($_POST[$uID.'_PA2']) ? '1' : '0';


    $productaccess3= isset($_POST[$uID.'_PA3']) ? '1' : '0';
    $productaccess4 = isset($_POST[$uID.'_PA4']) ? '1' : '0';
     $deleterecord = isset($_POST[$uID.'_DEL']) ? '1' : '0';
    $productaccess1a = "No";

    $productaccess2a = "No";

    $productaccess3a = "No";

    $productaccess4a = "No";



    $theirpassword = random_password($password);

// encrypts the randomly generated 8 digit password into 32 digit hash
    $their_password = md5($theirpassword);

   
}


    function random_password($password) {
         $vowels = 'aeuy';

        $consonants = 'bdghjmnpqrstvz';
        $length = 8;

         $strength = 4;
        if ($strength & 4) {
            $vowels .= "AEIOU";
            $consonants .= 'BDGHJLMNPQRSTVWXYZ23456789';
        }
        if ($strength &  {

            $consonants .= '@#$%';
        }
        $password = '';
        $alt = time() % 2;
        for ($i = 0; $i < $length; $i++) {
            if ($alt == 1) {

                $password .= $consonants[(rand() % strlen($consonants))];

                $alt = 0;
            } else {

                $password .= $vowels[(rand() % strlen($vowels))];
                $alt = 1;
            }

        }
        return $password;
    }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.