NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Debugger not able to handle header() calls?


Joined: 14 Feb 2004
Posts: 6
Reply with quote
Step by step I am getting there... not that easy to make the debugger work.

What I am trying to do is debug a user login page that uses a POST form. That page is (quite cleverly) called "login.php" and its code is mainly a huge switch statement that examines the value of a $_POST variable 'action'.
Here is a snippet of the code:
Code:
switch($action)
{
   case 'userlogin':
      DebugBreak();

      $logged_user_name = $_POST['user_name'];
...
      if (user_exists($logged_user_name))
      {
            save_user_profile($logged_user_name);
            header($header_location.'index.php?'.SID);
            exit;
      }
...
   default:
       DebugBreak();
       show_default('');
       break;
}


I load the page in my browser a first time, without any parameter and it switches to 'default', which displays the login page. I put the login and password in (the correct ones) and submit, which send to the same php script with the 'action' variable set to "userlogin". The DebugBreak does what it is supposed to do, I get control with phpED and can step through the code. All is well until I get to the line
Code:
            header($header_location.'index.php?'.SID);

At that stage, what should happen is that I get redirected to the index page since the login check found that all is well. When the debugger is disabled, that works fine. When it is enabled though, it just stops there and never redirects me.

Any idea why?
I suspect that might have to do with the fact (explained in a previous post) that when the debugger is enabled, all the HTTP headers are printed on the output (browser). Maybe they are printed on the output INSTEAD of being sent as headers, rather that in addition to being sent as headers as I assumed it was (some sort of debugging feature)

Any idea how to avoid that?

Cheers,
Wabiloo
View user's profileFind all posts by WabilooSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
While it's unclear from your post, I assume that the header() function is called with a properly formed string like this:
header("Location: http://myserver/mynewdir/mynewscript?myvars");. Anyways, please check it first.

Then you'd understand that instead of what you expected, header location does not make your web browser switching to target url immediately. It gets full the content and then re-requests new page by opening a new connection which means that you will get or will not get a new debug session, depending on if you sent appropriate debugger request or not. As far as I see you do not use any requests, but DebugBreak() function call. It's not a very convenient way. What IDE do you use ?
If you need an IDE that supports multisession debugging you'd give phped 3.3 a try.
View user's profileFind all posts by dmitriSend private messageVisit poster's website
output_buffering helps


Joined: 25 Sep 2004
Posts: 1
Reply with quote
I have been having similar problems with debugging across header("Location: . . .");
I realized today that enabling output_buffering was part of the problem. My pages have an include to a sitewide common header (include("/_include/ch.php")) which starts output buffering as its first action. However, that buffering does not seem to be operating inside a debug session on my Windows workstation. So -- I turned on the output_buffering directive in php.ini and voila, output buffering is working just fine in my debugging sessions. Just for the record, the reason this makes a difference to the header("Location: . . .") command is that you cannot send headers after output has already been started on a page. If you have any time of output happening before the Location header is sent, it will be ignored. So -- before I issue a header("Location:") I always issue a ob_end_flush() or ob_end_clean() -- just in case.

See http://www.php.net/header

And thanks to nusphere for coming up with a terrific product and a good support forum.

-jm
View user's profileFind all posts by jomofrodoSend private message
Debugger not able to handle header() calls?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic