NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Debug php script that is a POST

 
Post new topic   Reply to topic    NetBeans Forums -> PHP Users
View previous topic :: View next topic  
Author Message
faridz



Joined: 14 Mar 2011
Posts: 2
Location: Boston, MA

PostPosted: Mon Mar 14, 2011 1:33 pm    Post subject: Debug php script that is a POST Reply with quote

I have a php script that gets called when a user submits an html page form. I have set up php debugging in netbeans and I can debug the script successfully by making it the index file for the run configuration (but I get no _POST info in that case). What I need to do is debug the script when the user clicks the submit button in the html form so I can have access to the _POST global that contains the different values for the submits that I want to test.

How can I do this in NetBeans?
Back to top
jhsachs



Joined: 25 Dec 2010
Posts: 57
Location: Northern California

PostPosted: Wed Mar 16, 2011 7:26 pm    Post subject: Reply with quote

If I understand the question correctly, you want to stop the debugger in the page that is loaded after a form is submitted.

If that's right, you should be able to do it simply by making the debug configuration run the page that displays the form. When you submit the form, the debugger will stop at the first breakpoint in the following script (or the first statement in the script, if it is configured to do that).

Another useful technique is to test $_GET before $_POST when you process the form, so that you can simulate form submission by using parameters in the URL that you use to start the test. This is a more convenient way to test if you can perform several consecutive tests with the same form input. I have done this by putting code like the following near the start of the script:

Code:
if ( count($_GET) ) {
   $_POST = $_GET;
}

(I don't have the actual code on hand, so I won't guarantee that this is exactly what I did.)

Before the script goes into production, of course, you want to comment out this code so that users can't take advantage of it to bypass the form. Or write the code so that it will only take effect in a test environment.
Back to top
faridz



Joined: 14 Mar 2011
Posts: 2
Location: Boston, MA

PostPosted: Wed Mar 16, 2011 10:55 pm    Post subject: Reply with quote

jhsachs wrote:

If that's right, you should be able to do it simply by making the debug configuration run the page that displays the form. When you submit the form, the debugger will stop at the first breakpoint in the following script (or the first statement in the script, if it is configured to do that).


This does not appear to work.

My setup is like this:
index.html has the form
process.php processes the form data

I would like to break in the debugger in process.php after the user clicks the submit button in index.html and submits the form.

I set up Netbeans project run configuration index page to index.html and launch the debug run and index.html is loaded by the debugger in the web browser. On submitting the form, however, the debugger does not break on any of the break points in process.php unless I make that file the run configuration index file for the Netbeans project (in which case I would not have _POST global values)
Back to top
jhsachs



Joined: 25 Dec 2010
Posts: 57
Location: Northern California

PostPosted: Wed Mar 16, 2011 11:22 pm    Post subject: Reply with quote

I do this all the time. The only difference I see between your situation and mine is that you're starting the debug session with an HTML file instead of a PHP file.

Try changing the extension of the initial file to PHP (and changing the configuration accordingly). You shouldn't have to include any actual PHP code in the file.

If that doesn't work, consider attaching your files to a message posted here. I'll see what happens when I try to debug them myself. I probably won't have time to do it for several days, though. Perhaps someone else will be able to do it sooner.
Back to top
umbertofilippo



Joined: 08 Jan 2017
Posts: 1
Location: Milan

PostPosted: Sun Jan 08, 2017 3:04 pm    Post subject: Reply with quote

Thank you. I had the same problem and this solution solved the problem (NetBeans 8.2).
I set up my index page in the project configuration settings, making it a .php extension instead of .html, and setting a breakpoint in the called php code. Everything worked just fine. Thanks again!
Back to top
LukaCoder



Joined: 24 Sep 2013
Posts: 66

PostPosted: Mon Jan 09, 2017 11:58 am    Post subject: Use a Cookie Reply with quote

Hi,

to debug POST page, you can add a persistent COOKIE named "XDEBUG_SESSION_START" with value "netbeans-xdebug"; if you run the netbeans debugger, all should work without changes in your code.
Back to top
Saygameoni



Joined: 20 Mar 2017
Posts: 2

PostPosted: Mon Mar 20, 2017 3:06 am    Post subject: Reply with quote

It is more readable to understand.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> PHP Users All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo