Jump to content

Fatal error: Cannot redeclare encode() (previously declared


droopz17

Recommended Posts

include_once("includes/functions.php");

$test = encode('whatever');

 

 

The actual code is to encode my cookies so i rather not include it. I just need to know why any time i make a function in a seperate file then include it, if i use it more than once in my site it gives me a fatal error.

Link to comment
Share on other sites

Do the files included have a .php or .inc extension? I remember something about needing a .inc extension on included php files if you want them to be parsed.

 

No it still is not working, please someone help me. I want my functions in a seperate file so i have it organized. I do not want to resort to putting it in my pages.

Link to comment
Share on other sites

that error is basically saying that you have called it once, somewhere, then in the same block of code being parsed it is being called again. i've only really seen it with classes, so paste some of the code so we can take a look.

 

 

 

include_once("include/encoder.inc");
$ad_encode = encode('admin_rights');


<?php
function encode($var){

$out_var = '';
$s = '0';
$e = '1';

$num_char = strlen($var);

//WHILE NUMBER OF CHARACTERS IS LESS THE THE NUMBER OF I
while( $i < $num_char ){
	$new_var = substr($var, $s, $e );

	//long if statement goes here.


	$s++;

$i++;
}
return $out_var;

}



function decode($var){

$out_var = '';
$s = '0';
$e = '2';

$num_char = strlen($var);

//WHILE NUMBER OF CHARACTERS IS LESS THE THE NUMBER OF I
while( $i < $num_char ){
	$new_var = substr($var, $s, $e );

	//long if statement goes here.


	$s++;
	$s++;

$i++;
$i++;
}
return $out_var;

}

?>

Link to comment
Share on other sites

Are you using include_once() instead of just include() for a reason?

 

 

I thought that might help, but either way it still give the fatal error, is there a way to exit from the include once you use it.  kinda like when you use mysql you can close it with mysql_close

Link to comment
Share on other sites

files containing PHP must have the .php extention. kind of silly making it .inc

 

if you just make a php file with the include and calling the encode function, does it spit out any errors? fatal errors?

 

 

 

 

Fatal error: Cannot redeclare encode() (previously declared in include/encoder.inc:2) in include/encoder.php on line 2

Link to comment
Share on other sites

move your includes inside your document.  The issue is your document can't handle those includes because it doesn't know your inside php

NO:

include_once("include/encoder.inc");

$ad_encode = encode('admin_rights');

<?php

 

YES:

<?php

 

include_once("include/encoder.inc");

$ad_encode = encode('admin_rights');

 

 

Link to comment
Share on other sites

that error is basically saying that you have called it once, somewhere, then in the same block of code being parsed it is being called again. i've only really seen it with classes, so paste some of the code so we can take a look.

 

I am agree with ProjectFear.

Did u include this file in other scripts, if so then may be there u include that file previously.

Link to comment
Share on other sites

but the OP said that they made a BLANK file except for the include and the calling of the function adn received an error.

 

<?php
include('includes/encoder.php');
$encode = encoder('text');
?>

 

OP said that that spat out errors.

 

Link to comment
Share on other sites

My code is inside my <?php  ?>, php lines. I have a site with like over a 100pages all going off a template, basically a header and footer that is included in each page i code. I have one page that request it but request the encode() fuctions like 5 times. but is only included once.

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.