Jump to content

[SOLVED] A function is trying to redeclare itself on top of itself


jordanwb

Recommended Posts

I'm trying to improve PHProxy that available here by using mcrypt. A few months ago I asked a question regarding encryption methods. I was pointed to this page, I'm trying to implement those two functions (made a modification to the params). Now I put those to functions plus a key generator into a separate file called encryption.php Now in PHProxy's index.php on the third line I put

 


include "encryption.php";

 

to include those three functions. But I get this error:

 

Fatal error: Cannot redeclare linencrypt() (previously declared in /var/www/localhost/htdocs/proxy/encryption.php:3) in /var/www/localhost/htdocs/proxy/encryption.php on line 9

 

I searched php.net and it doesn't have a record of linencrypt or lindecrypt. On line 9 in encryption.php is a closing curly bracket. Also if I go to the file directly I don't get the error.

 

encryption.php:

 

<?php

function linencrypt($pass, $key)
{
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); //get vector size on ECB mode
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); //Creating the vector
        $cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $pass, MCRYPT_MODE_ECB, $iv); //Encrypting using MCRYPT_RIJNDAEL_256 algorithm
        return $cryptedpass;
} // <- This is line 9

function lindecrypt($pass, $key)
{
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $decryptedpass = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $key, $pass, MCRYPT_MODE_ECB, $iv); //Decrypting...
        return rtrim($decryptedpass);
}

function GenerateRandomKey ($length)
{
// start with a blank password
$password = "";

// define possible characters
$possible = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

// set up a counter
$i = 0; 

// add random characters to $password until $length is reached
while ($i < $length)
{ 

	// pick a random character from the possible ones
	$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);

	// we don't want this character if it's already in the password
	if (!strstr($password, $char))
	{ 
		$password .= $char;
		$i++;
	}
}
// done!
return $password;
}

?>

 

I want to implement this encryption so that for each session a different key is used so that the encrypted site url isn't retrieved. I'm running Gentoo Linux 2008.0 with PHP Version 5.2.26-r6

Link to comment
Share on other sites

The file that the maker of PHProxy wrote is 1100+ lines of code. Here's the first couple of dozen:

 

<?php

// I added from here
include "encryption.php";

session_start ();

if (empty ($_SESSION['mcrypt_key']))
{
$_SESSION['mcrypt_key'] = GenerateRandomKey (32);
}
// To here
/*
   +-----------------+------------------------------------------------------------+
   |  Script         | PHProxy                                                    |
   |  Author         | Abdullah Arif                                              |
   |  Last Modified  | 5:27 PM 1/20/2007                                          |
   +-----------------+------------------------------------------------------------+
   |  This program is free software; you can redistribute it and/or               |
   |  modify it under the terms of the GNU General Public License                 |
   |  as published by the Free Software Foundation; either version 2              |
   |  of the License, or (at your option) any later version.                      |
   |                                                                              |
   |  This program is distributed in the hope that it will be useful,             |
   |  but WITHOUT ANY WARRANTY; without even the implied warranty of              |
   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
   |  GNU General Public License for more details.                                |
   |                                                                              |
   |  You should have received a copy of the GNU General Public License           |
   |  along with this program; if not, write to the Free Software                 |
   |  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
   +------------------------------------------------------------------------------+
*/

error_reporting(E_ALL);

 

What about the mcrypt libraries for Gentoo: http://gentoo-portage.com/Search?search=mcrypt

Link to comment
Share on other sites

Damn I'm an idiot. I was including the file twice but I didn't know it.

 

There are two PHProxy files: index.php and index.inc.php I put the include it both files. But what I didn't know is that index.php included index.inc.php

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.