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

Asked

Viewed 63 times

2

When I start Debugger php7.0 CLI with this php.ini setting:

;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 enters the if and arrives at header('Location:login.php'); but does not go to the login.php page. Instead gets out of parole if passing through the includes reaching the end of the file. Does not direct to the " include $fullpath; ".

It is worth remembering that in normal execution the program works 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’s installed the part.

( explaining that part - I installed Lampp that comes with Mysql, apache and Proftpd together. In the search for a debugger I found the instructions to download php5.1 made $ sudo apt-get install php5-Xdebug configured php.ini as reported in http://www.diogomatheus.com.br/blog/php/depuracao-de-aplicacoes-php-com-xdebug/ . Only then I realized that in reality I am with two Apaches one called Apache and the other Apache2, if I understood correctly. The thing is that I am with two php.ini, however I took care to configure both 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";
}
?>

1 answer

0

The Debugger enters if and arrives at header('Location:login.php'); but it does not go to the login.php page.

To understand the actual functioning, it is necessary to understand how the header function and how it is treated.

PHP.net:

header - Send a raw HTTP header

Basically, the header sends an HTTP header to the browser. The header output is nothing but plain text. Roughly speaking, it is a echo specific to headers and ignoring the output buffer (output buffer).

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

PHP does not know how to execute redirects, the command header('location:login.php') sends the redirect header to the browser and who runs the redirect is the browser itself.

Another detail is that the header does not interrupt code execution. It is recommended to use a die, exit or return shortly after the header.

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

When the browser receives the redirect header, the browser redirects to you.

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

This occurs, too, by the place you are running the code.

When to start the Debugger php7.0 CLI with this php.ini configuration:

In all the explanation, I emphasized the use of browser. All redirection is carried out only by the browser.

In your case, you are running your code via CLI (Command-line interface). PHP CLI does not redirect because it does not use the HTTP protocol (the protocol used by the browser). So much so that PHP CLI ignores completing the execution of header.

Hence, as the execution of the header is completely ignored and it does not interrupt the execution of the script, it is normal Debugger continue executing the code as if nothing had happened.

Does not direct to the " include $fullpath; ".

I couldn’t find your code include $fullpath.

More information:

https://stackoverflow.com/a/8083152/1628790

https://stackoverflow.com/a/11894758/1628790

https://stackoverflow.com/a/20932511/1628790

  • include $fullpath is on the body. I include include the top.php include which is where the menu is. Then the "body" of the site and then the post buttom.php that is the footer. Basically I just change the contents of the middle page of the site.

  • Just one thing. How to test the site by the Debugger? I have a problem loading some items and I would like to debug all the steps until you arrive at the page with the problem. This is impossible in php ? In java it is soft to walk all over the code, step by step. Already in php ....

  • Call to where Gabriel?

  • It refers to the right button in index.php -> debug as -> php CLI application ? It follows github if you want to be more. https://github.com/FabianoSouzaPereira/myschool.com.br

  • I ended up traveling here, which IDE are you using? I haven’t touched xDebugger in a while. I will run some tests later to understand why.

  • Eclipse Java EE IDE for Web Developers. Version: Oxygen.1a Release (4.7.1a) Build id: 20171005-1200

  • 1

    @Fabianodesouzapereira sorry for the delay, but I could not find relationship between Xdebug and the problem you present with the include/require. I couldn’t find any configuration that could compromise this, so I believe it is the form (or IDE) you are using. Maybe try another, like Phpstorm, Netbean or Zendstudio to see if the same occurs. As your question was more focused on the header, I believe that your question may/should be another question.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.