Welcome Guest, Not a member yet? Register   Sign In
Controller called twice
#1

[eluser]emorling[/eluser]
My controller get's called twice. This is the controller function I run.

Code:
function dosell($char_id, $item_id){
        $this->output->enable_profiler(TRUE);    
            
        log_message('debug', "STARTUP DOSELL($char_id, $item_id)");
        
        $char = new Character(); $char->get_by_id($char_id);
        $item = new Item(); $item->get_by_id($item_id);
        if(!$item->exists()){
            log_message('debug', "ITEM DOES NOT EXIST");
            die("item does not exists $char_id  $item_id");
        }        
                log_message('debug', "ITEM DOES EXIST");
        $item->delete();        
        die("item  exist");            
    }

And this is the DEBUG LOG:

Quote:DEBUG - 2009-09-17 19:43:38 --> Config Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Hooks Class Initialized
DEBUG - 2009-09-17 19:43:38 --> URI Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Router Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Output Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Input Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Global POST and COOKIE data sanitized
DEBUG - 2009-09-17 19:43:38 --> Language Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Loader Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: url_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: utilities_helper
DEBUG - 2009-09-17 19:43:38 --> Database Driver Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/datamapper_lang.php
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: inflector_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: security_helper
DEBUG - 2009-09-17 19:43:38 --> Config file loaded: config/datamapper.php
DEBUG - 2009-09-17 19:43:38 --> Session Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: string_helper
DEBUG - 2009-09-17 19:43:38 --> A session cookie was not found.
DEBUG - 2009-09-17 19:43:38 --> Session routines successfully run
DEBUG - 2009-09-17 19:43:38 --> Controller Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Session class already loaded. Second attempt ignored.
DEBUG - 2009-09-17 19:43:38 --> Model Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: cookie_helper
DEBUG - 2009-09-17 19:43:38 --> STARTUP DOSELL(25, 459)
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: form_helper
DEBUG - 2009-09-17 19:43:38 --> Form Validation Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/form_validation_lang.php
DEBUG - 2009-09-17 19:43:38 --> ITEM DOES EXIST
DEBUG - 2009-09-17 19:43:38 --> Config Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Hooks Class Initialized
DEBUG - 2009-09-17 19:43:38 --> URI Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Router Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Output Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Input Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Global POST and COOKIE data sanitized
DEBUG - 2009-09-17 19:43:38 --> Language Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Loader Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: url_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: utilities_helper
DEBUG - 2009-09-17 19:43:38 --> Database Driver Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/datamapper_lang.php
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: inflector_helper
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: security_helper
DEBUG - 2009-09-17 19:43:38 --> Config file loaded: config/datamapper.php
DEBUG - 2009-09-17 19:43:38 --> Session Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: string_helper
DEBUG - 2009-09-17 19:43:38 --> Session routines successfully run
DEBUG - 2009-09-17 19:43:38 --> Controller Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Session class already loaded. Second attempt ignored.
DEBUG - 2009-09-17 19:43:38 --> Model Class Initialized
DEBUG - 2009-09-17 19:43:38 --> STARTUP DOSELL(25, 459)
DEBUG - 2009-09-17 19:43:38 --> Helper loaded: form_helper
DEBUG - 2009-09-17 19:43:38 --> Form Validation Class Initialized
DEBUG - 2009-09-17 19:43:38 --> Language file loaded: language/english/form_validation_lang.php
DEBUG - 2009-09-17 19:43:38 --> ITEM DOES NOT EXIST

See the bolded items above. This confirms that the controller is run twice.

I ran Fiddler with Firefox and it does not make two browser requests.

Any ideas?
#2

[eluser]OverZealous[/eluser]
Try putting this in your function:
Code:
$debug = debug_backtrace();
        echo "\n<pre>STACK TRACE:\n";
        $counter = 0;
        foreach($debug as $d) {
            // skip the first line which is this method
            if($counter > 0) {
                if($counter < 10) {
                    $counter = ' '.$counter;
                }
                echo "$counter: ";
                if(isset($d['class'])) {
                    echo $d['class'] . '.';
                }
                echo $d['function'].'()';
                
                if(isset($d['file'])) {
                    echo ' - '.$d['file'] . ': ' . $d['line'];
                }
                echo "<br/>\n";
            }
            $counter++;
        }
        echo "</pre>\n";

It's a bit of stacktrace-like code that will help you figure out what called the current PHP function.
#3

[eluser]emorling[/eluser]
Quote:STACK TRACE:
1: call_user_func_array() - /home/em/public_html/game/system/codeigniter/CodeIgniter.php: 232

2: require_once() - /home/em/public_html/game/index.php: 115

I get this. Can we draw any conclusion?
#4

[eluser]OverZealous[/eluser]
That's it? Then it's like I said, you are most likely getting two complete calls from the client, or at the server level. Those are the normal startup methods for a CodeIgniter controller.

If you were getting some kind of internal calling, you'd see a much longer stacktrace.

(You might want to throw it at the end of the method, to see if it is different.) Play around with it some more. You have all of the sources to CodeIgniter, so you can usually follow the function threads as you work. If I remember correctly, the "line number" doesn't always match up with the file name. You might have to be creative ;-)
#5

[eluser]emorling[/eluser]
Thanks will do. I just don't understand why it only happens when I leave the $item-delete method in. When I take it out it works fine.

Even if I run this it runs twice:
$it = new Item();
$sql = "DELETE FROM `items` WHERE `id` = ".$item->id;
$it->query($sql);
#6

[eluser]OverZealous[/eluser]
I think it's running twice no matter what, you just only see it after you delete the item, because you are dieing. That might be your problem, as well. Don't use die unless it's a serious server-side error. You are sending information back to the browser that something went wrong when you use that.

Just return from your method, instead, or use CodeIgniter's show_error().
#7

[eluser]emorling[/eluser]
Ugh.... you are not going to believe this...

I checked my ci_sessions table and there was an unknown IP adress in there, which is impossible because this is on a very obscure adress.

Somehow a call was made from an IP in ANOTHER country with Mozilla to each page I visit. That is why two calls were made, but I could not detect them with Fiddler.

I added the IP to the banned list of my site, and it fixed it.

Any security experts here? Is this some kind of trojan behavior?
#8

[eluser]OverZealous[/eluser]
Yuck. Sounds like a virus/trojan/keylogger situation.

Are you using Windows? If so, you might have the AntiVirus Pro (goes by many other names) virus. My parents just got hit by it (it's incredibly sneaky), and it's a PITA rootkit that (amazingly) can be removed. However, it took me a whole weekend of remote support to get their computer cleaned.

One possible link. Good luck!
#9

[eluser]emorling[/eluser]
Thanks will try. Im now running an online Trojan scanner.
#10

[eluser]emorling[/eluser]
Thanks, I used the Malware Removal software and found a trojan. Hopefully that solves it.




Theme © iAndrew 2016 - Forum software by © MyBB