Why does Debugger skip line with header, not going to the link?

2

When I start the php7.0 CLI debugger with this php.ini configuration:

;extension=php_soap.dll
;extension=php_sockets.dll
;extension=php_sqlite3.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
extension=pdo.so
extension=pdo_mysql.so

; XDEBUG Extension

zend_extension = "path"

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[xdebug]
xdebug.remote_enable = On
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = On
xdebug.remote_autostart = 0
xdebug.remote_handler= "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.remote_mode = "req"
xdebug.remote_port = 9000

[CLI Server]
; Whether the CLI web server uses ANSI color coding in its terminal output.
cli_server.color = On

The debugger goes into if and arrives at header ('location: login.php'); but it will not go to the login.php page. Instead it exits the if conditional by passing the includes statements to the end of the file. It does not point to "include $ fullpath;".

It is worth remembering that in normal execution the program works it enters the login the database returns the search is verified the veracity of the data and then access to the initial page of the program. Of course I use the apache that is installed the part.

  

(explaining this part - I installed Lampp that comes with Mysql, Apache and Proftpd together. In searching for a debugger I found the instructions to download php5.1 I made $ sudo apt-get install php5-xdebug I set up php. ini as informed on link .   Only then I realized that in fact I am with two Apaches one named apache and the other apache2, if I understood correctly. The thing is that I'm with two php.ini, however I was careful to set the two in the same way.)

What happens to the path ignored by the debugger? Why does it ignore the header path?

?php
session_start();

if( !(isset($_SESSION['login']) && $_SESSION['login']==true) ){
header('location:login.php');
}  


include 'application/dao/Connection.php';
include 'biblioteca/Conversor.php';
include 'biblioteca/Validator.php';

if( isset($_GET['page']) ){
  $page = $_GET['page'];
  $php='';
  $class='';
  $folder='';
  $fullpath='';
if(strpos($page, "_")!= 0){
    $vetor = explode("_", $page);
    $folder = $vetor[0];
    $class = $vetor[1];

}else{
    $file = "";
    $class = "";
} 

$fullpath = "$folder/$class.php";

if(file_exists($fullpath) == false){
    $fullpath = "begin.php";
}   
} else {
  $fullpath = "begin.php";
}
?>
    
asked by anonymous 25.10.2017 / 17:53

1 answer

1
  

The debugger goes into if and arrives at header ('location: login.php'); but it will not go to the login.php page.

To understand how it works, you need to understand how header works and how it works.

PHP.net:

  

header - Send a raw HTTP header

Basically, header sends an HTTP header to the browser. The output of the header is nothing more than pure text. Grossly speaking, it is a% specific for headers and ignores the output buffer .)

In the case of a header with echo , what is sent to the browser is that a targeting should be performed.

PHP does not know how to perform redirects, the location command sends the redirection header to the browser and the redirection is the browser itself.

Another thing is that header('location:login.php') does not interrupt code execution. It is therefore recommended to use header , die or exit soon after return .

header('location:login.php');
die();

When the browser receives the redirect header, the browser performs the redirect for you.

  

What happens to the path ignored by the debugger? Why does it ignore the header path?

This is also true of the place you are running the code.

  

When I start the debugger php7.0 CLI with this php.ini configuration:

Throughout the explanation, I emphasized the use of browser. All redirection is done only by the browser.

In your case, you are running your code via the CLI ( commando-line interface ). PHP CLI does not perform redirects because it does not use the HTTP protocol (which is used by the browser). So much so, PHP CLI ignores completion of header .

As soon as the execution of header is completely ignored and it does not interrupt the execution of the script, it is normal for the debugger to continue executing the code as if nothing had happened.

  

Does not direct to "include $ fullpath;".

I did not find the header in your code.

More information:

link

link

link

    
25.10.2017 / 18:29