2

I'm trying to debug a web application based on the CodeIgniter (2.x) framework. I've tried var_dumping $_SERVER and recreating this at the beginning of my debugging session (bootstrapping phpdbg).

$ phpdbg -e index.php
phpdbg> ev require('boostrap.php');
phpdbg> run

However it gives me a 404. even though requesting the page through the browser gives me the correct result. could somebody tell me how to properly bootstrap phpdbg so it loads the correct page in codeigniter? this is my bootstrapping code, if it helps.

<?php
$_SERVER = array (
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv: 38.0) Gecko/20100101 Firefox/38.0',
    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
    'HTTP_ACCEPT_ENCODING' => 'identity,gzip,deflate',
    'HTTP_CONNECTION' => 'keep-alive',
    'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
    'SERVER_SIGNATURE' => '<address>Apache/2.4.12 (Ubuntu) Server at api.timzwart.local.mybit.nl Port 80</address>',
    'SERVER_SOFTWARE' => 'Apache/2.4.12 (Ubuntu)',
    'SERVER_NAME' => 'api.timzwart.local.mybit.nl',
    'SERVER_ADDR' => '192.168.1.35',
    'SERVER_PORT' => '80',
    'REMOTE_ADDR' => '192.168.1.35',
    'DOCUMENT_ROOT' => '/var/www/vhosts/api.timzwart.local.mybit.nl',
    'REQUEST_SCHEME' => 'http',
    'CONTEXT_PREFIX' => '',
    'CONTEXT_DOCUMENT_ROOT' => '/var/www/vhosts/api.timzwart.local.mybit.nl',
    'SERVER_ADMIN' => 'webmaster@localhost',
    'SCRIPT_FILENAME' => '/var/www/vhosts/api.timzwart.local.mybit.nl/index.php',
    'REMOTE_PORT' => '40706',
    'GATEWAY_INTERFACE' => 'CGI/1.1',
    'SERVER_PROTOCOL' => 'HTTP/1.0',
    'REQUEST_METHOD' => 'GET',
    'QUERY_STRING' => '',
    'REQUEST_URI' => '/events/185151',
    'SCRIPT_NAME' => '/index.php',
    'PATH_INFO' => '/events/185151',
    'PATH_TRANSLATED' => 'redirect:/index.php/events/185151/185151',
    'PHP_SELF' => '/index.php/events/185151',
    'REQUEST_TIME_FLOAT' => 1435128205.281,
    'REQUEST_TIME' => 1435128205,
    'REDIRECT_URL' => '/events/185151',
    'REQUEST_URI' => '/events/185151',
    'argv' => array('events','185151'),
);
?>
timwaagh
  • 303
  • 3
  • 14
  • Your bootstrap file retrieves the debugging session configuration, you still need the exec index.php , then the run command. What I do is to capture a $_SERVER from a real session and use it as a bootstrap.php – mrbarletta Jul 01 '15 at 19:05
  • I used the -e command line switch so the execution context is already set (so there is no need to use exec). this worked for a codeigniter-cli program however not for this web application. Indeed this $_SERVER is also pretty much copied from a real session but that did not work for me. I added argv to it because REQUEST_URI did not work for routing in the way it normally does. – timwaagh Jul 03 '15 at 08:37
  • Did u tried to setup the rest of the global variables? Maybe code igniter uses $_REQUEST/ $_POST / $_GET . I set all those as well and works ! I usually do a $_SERVER dump + print_r(get_defined_vars(),1); with those variables I am sure I have everything I need. – mrbarletta Jul 04 '15 at 16:30
  • well im still trying to figure it out. no its not one of those, i dont think it uses them, but it might have to do with the config.php in codeigniter. – timwaagh Jul 09 '15 at 07:43
  • here is one of the problems i think. how to make sure the STDIN onstant is not defined? this constant is defined by the CLI sapi. and of course is not defined when doing web requests. codeigniter checks for this. i could redefine it with the runkit extension in theory however in practise that would likely mean re-compilation of php and i have experienced significant troubles with that. – timwaagh Jul 09 '15 at 09:07
  • runkit doesnt work either because its a nonuser constant – timwaagh Jul 09 '15 at 10:52
  • so this question will be important for the solution. http://stackoverflow.com/questions/31315783/remove-non-user-constant-php – timwaagh Jul 09 '15 at 12:14

2 Answers2

0

Well, you can always check printing that constant from the phpdbg cli and see if its defined. You will have to start creating breaks on codeigniter code .. find the file:line that return the 404 and add a break there or before and go step by step, if something is missing you will find out.

mrbarletta
  • 902
  • 11
  • 17
0

A possible solution, if you can edit your version of the framework itself is to look for all lines referring to the input method and edit those to accept some fabricated debuging constant as well. It becomes like this. you can then set the constant with ev in phpdbg prior to the actual debugging.

system/core/Input.php:      return (!defined('DEBUGGING_FAKE_WEBREQUEST') AND (php_sapi_name() === 'cli' OR defined('STDIN')));
system/core/URI.php:            if (!defined('DEBUGGING_FAKE_WEBREQUEST') AND (php_sapi_name() == 'cli' or defined('STDIN')))
timwaagh
  • 303
  • 3
  • 14