Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fatal error: Cannot redeclare logincheck() (previously declared in /home/fxuup/public

    Fatal error: Cannot redeclare logincheck() (previously declared in /home/fxuup/public_html/includes/functions.php:87) in /home/fxuup/public_html/functions.php on line 103


    iv been having this problem in my functions.php . i just cant figure whats wrong with it.


    Code:
    unction logincheck(){
    
    
    if (empty($_SESSION['username'])){
    echo "
    <SCRIPT LANGUAGE='JavaScript'>
    window.location='index.php';
    
    </script>
    ";
    exit();
    }}
    
    ////UPDATE ONLINE
    $time = time() + (60 * 10);
    mysql_query("UPDATE users SET online='$time' WHERE username='$username'");
    ///FINSH UPDATING ONLINE
    
    function makecomma($input)
    {
    
    if(strlen($input)<=3)
    { return $input; }
    $length=substr($input,0,strlen($input)-3);
    $formatted_input = makecomma($length).",".substr($input,-3);
    return $formatted_input;
    }
    Last edited by fxuup; 08-23-2010 at 08:13 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You cannot create a function called logincheck() in both /home/fxuup/public_html/functions.php and /home/fxuup/public_html/includes/functions.php. Given the error, /home/fxuup/public_html/functions.php is including /home/fxuup/public_html/includes/functions.php into it, and has imported any of its function definitions (such as logincheck()). PHP does not support function overloading or overriding, so you cannot actually rewrite the logincheck in /home/fxuup/public_html/functions.php. If it functions equivalently you won't need to worry about it since it already exists in the scope of /home/fxuup/public_html/functions.php once its been included in. If its different, you need to rename the logincheck in /home/fxuup/public_html/functions.php to something different and modify the accessing calls appropriately.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright thank you i didnt notice i had a duplicated functions.php file. but i have deleted the one i don't need. and than i still get this as well


    Fatal error: Cannot redeclare logincheck() (previously declared in /home/fxuup/public_html/includes/functions.php:88) in /home/fxuup/public_html/includes/functions.php on line 96

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Then the same problem exists in /home/fxuup/public_html/includes/functions.php itself as well. That file has two definitions for the logincheck function. Delete the second one starting at line 96.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    it's telling you what the problem is

    you have two instances of "logincheck" in that file

    you could do

    PHP Code:
    if(!function_exists('logincheck')) 
    {
        function 
    logincheck()
        {
            
    /* code */
        
    }

    as a prevention

    also note if you're using this within a class you should use method_exists as, a function is a method in OOP.

  • #6
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so somthing like this?

    PHP Code:
    if(!function_exists('logincheck')) 
    {
        function 
    logincheck()
        {
           if (empty(
    $_SESSION['username'])){
    echo 
    "
    <SCRIPT LANGUAGE='JavaScript'>
    window.location='index.php';

    </script>
    "
    ;
    exit();
        }


  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That works yes, but what it means is that if the logincheck() function has previously been declared, this one will not overwrite it (what you have here will not be called when logincheck() is called).

    There are only two ways to redeclare functions in PHP. The first is by using PHP5.3+ namespaces to create different functions. These are then called by customNamespaceName\sameNamedFunc();, so its a semi-override/overload, but not a real one, and the other way is adding in the advanced PHP debugger which allows you to call override_function and rename_function. This is exceedingly handy when using debugging functionality, but should not be used for production work since APD is not a common installation.

    Class methods can be overridden, but still not overloaded (late static binding is a new feature too... 5.3 I think is when it came into effect?). Using polymorphism you can switch at runtime the called method based on the object present.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #8
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry im fairly new to php coding. Could you show me a example?
    But when i put that code in i get

    Parse error: syntax error, unexpected $end in /home/fxuup/public_html/includes/functions.php on line 838


    But line 838 in the last line of the functions.php file.

    PHP Code:
    ?> 
    Thats all it contains.
    Last edited by fxuup; 08-23-2010 at 09:14 PM.

  • #9
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    line numbers are only approximate

    that error means that your curly bracers are unbalanced

    correct formatting helps with this considerably:

    PHP Code:
    <?php
    if(!function_exists('logincheck')) 
    {
        function 
    logincheck()
        {    
            if (empty(
    $_SESSION['username']))
            {
                echo 
    "<SCRIPT LANGUAGE='JavaScript'>window.location='index.php';</script>";
                exit(); 
            }
        }
    }  
    ?>
    Last edited by met; 08-23-2010 at 09:18 PM. Reason: fixed my formatting __^

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Can't believe I missed that >.<
    Also, don't bother with a Javascript redirection, just use a header('Location: index.php'); instead. The exit/die function is still required when using a header otherwise it will continue to process the remaining page.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #11
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright well that work perfect but now i got another error.

    Fatal error: Cannot redeclare makecomma() (previously declared in /home/fxuup/public_html/includes/functions.php:105) in /home/fxuup/public_html/includes/functions.php on line 113

    PHP Code:
    function makecomma($input)
    {

    if(
    strlen($input)<=3)
    { return 
    $input; }
    $length=substr($input,0,strlen($input)-3);
    $formatted_input makecomma($length).",".substr($input,-3);
    return 
    $formatted_input;


  • #12
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    there's being new to something and there's being just plain stupid

    it's the same error as the previous one, work it out

  • #13
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i can't work this out im not the greatest.

    i got this so far
    PHP Code:
    if(!function_exists('makecomma'))
    {
        function 
    makecomma($input)
        {
        if(
    strlen($input)<=3)
    { return 
    $input; }
    $length=substr($input,0,strlen($input)-3);
    $formatted_input makecomma($length).",".substr($input,-3);
    return 
    $formatted_input;
    }

    Nevermind. Im gett the hang of functions now. Thanks guys for all the help.
    Last edited by fxuup; 08-23-2010 at 10:05 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •