FifthTimeRegistering Posted July 6, 2007 Share Posted July 6, 2007 Hi - I have been using OSC and PHP for sometime now but the $_POST variables make me crazy. In the sites I have created I output $_POST, $_GET AND $_SESSION at the end of the html if I am in debug mode. This works great for debugging. I have been unable to do this with OSC because there are so many redirects that these have been flushed before the end of the html file. I recently tried again by adding: ob_start(); echo "<pre>"; var_dump($HTTP_POST_VARS); echo "</pre>"; echo "<pre>"; var_dump($_POST); echo "</pre>"; echo "<pre>"; var_dump($HTTP_GET_VARS); echo "</pre>"; to the top of application_top.php and $page_contents = ob_get_contents(); ob_end_clean(); echo $page_contents; at the end of application_bottom.php Here is a typical response to the "Add to Cart" from product_info.php array(0) { } array(0) { } array(2) { ["cPath"]=> string(2) "66" ["products_id"]=> string(3) "151" } The add product action uses the post method but there is nothing in the $_POST variable or $HTTP_POST_VARS. Where is it? Here is the main code for that form with the extra html removed: <form name="cart_quantity" action="catalog/product_info.php?cPath=66&products_id=151&action=add_product" method="post"> Quantity: <input type="text" name="quantity" value="1" size="2"> <input type="hidden" name="products_id" value="151"> <input type="image" src="includes/languages/english/images/buttons/button_in_cart.gif" border="0" alt="Add to Cart" title=" Add to Cart "></form> Clearly this is a post form and there should be a $_POST variable bit there is not. Since OSC requires disabled register_globals I went to import_request_variables() but that only gives me some of the variables. For the form above, it outputs $prodcuts_id but not $quantity. I even added: $arr = get_defined_vars(); echo "<pre>"; var_dump($arr); echo "</pre>"; to the top of application_top.php and there was no $_POST variable and no $HTTP_POST_VARS. Actually they were blank and $quantity was still missing. Can someone please explain this? Thanks, Rick The Grub Club® - Restaurant Menus Link to comment Share on other sites More sharing options...
dynamoeffects Posted July 6, 2007 Share Posted July 6, 2007 That was a bit confusing, but I can tell you that after adding an item to cart, the page will refresh to avoid the "Do you want to repost this information" message box. That means that you have to add a die() to the code in order to actually see the output. The code above is a bit complex for what you're wanting to do assuming that you don't have STS or BTS installed. Something like this is what I use when I need to debug a page: echo '<pre>'; die(print_r($_POST)); echo '</pre>'; You don't need to mess with output buffers unless you have a templating system installed. Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail. Link to comment Share on other sites More sharing options...
FifthTimeRegistering Posted July 6, 2007 Author Share Posted July 6, 2007 That was really helpful !!! I can actually see the $_POST variables for the first time. Is there any way to save them to a log file. I am able to do it with the $_GET variable but $_POST is blank in the log file. Thanks Again for the Assistance, I really appreciate it. Rick echo '<pre>'; die(print_r($_POST)); echo '</pre>'; The Grub Club® - Restaurant Menus Link to comment Share on other sites More sharing options...
dynamoeffects Posted July 6, 2007 Share Posted July 6, 2007 Something like this should work: $post_vars = print_r($_REQUEST, true); $fo = fopen('temp.txt', 'a'); fwrite($fo, $post_vars . "\r\n\r\n"); fclose($fo); And of course you'll need a file called temp.txt in the same directory chmod'd to 777. Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail. Link to comment Share on other sites More sharing options...
FifthTimeRegistering Posted July 6, 2007 Author Share Posted July 6, 2007 This is starting to make sense! Here is how I accomplished outputing both $_GET and $_POST to a file: $f_time = date("h:m:s"); $filename = "htdocs/www/catalog/admin/tep/catalog-log.html"; $fp = fopen($filename, "a") or die("Couldn't open file"); fputs($fp, "<font color='#FF0000'>Start Data</font><br>"); fputs($fp, "Time: " . $f_time); fputs($fp, "<br>----------------<br>"); $post_vars = "\$_POST<pre>" . print_r($_POST, true) . "</pre>"; fwrite($fp, $post_vars . "\r\n\r\n"); fputs($fp, "<br>----------------<br>"); $post_vars = "\$_GET<pre>" . print_r($_GET, true) . "</pre>"; fwrite($fp, $post_vars . "\r\n\r\n"); fputs($fp, "<br>----------------<br>"); fputs($fp, "<font color='#FF0000'>End Data</font><br>"); // newline to end the headers section fputs($fp, "<br>----------------<br>"); fclose($fp); This outputs to a html file which I have opened in another browser window. After each step in OSC I can refresh the logging page and see what was added. It has to append the file because it goes through the application_top.php file twice as was described earlier. The first time through $_POST is there and the second time it is gone. Now I have another question. How do I output the session variable? It is stored in the database so the above method doesn't work. Thanks!! The Grub Club® - Restaurant Menus Link to comment Share on other sites More sharing options...
dynamoeffects Posted July 6, 2007 Share Posted July 6, 2007 tep_session_id() or just session_id() Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.