04-12-2017, 03:38 AM
I have a situation where I post form to php parser via ajax call:
Example
$.post('parser.php', {
post_var1:var1,
post_var2:var
},
function(data)
{
console.log("Response: "+data);
});
then in the parser.php I submit this data to db. So I need to include init.php, header.php and securePage in the parser.
Example
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/users/init.php';
require_once $abs_us_root.$us_url_root.'users/includes/header.php';
if (!securePage($_SERVER['PHP_SELF'])){die();}
if($f_var1 = $_POST['post_var1'] ) $fields[var1] = $f_var1;
if($f_var2 = $_POST['post_var2'] ) $fields[var2] = $f_var2;
$success = $db->insert('devices',$fields);
if(success) echo "1";
else echo "0";
?>
This should be pretty straight forward right?
Well the problem is that when I get echo from parser.php, the console.log prints the whole header (users/includes/header.php) + my echo 0 or 1.
I tryed to flush() and ob_flush() and then echo with no success. Problem occurs when I include header.php. If header.php is not included, the echo works OK. But then I'm stuck without DB class...
I also searched header.php and not found any of the echo routines. Also header.php is still original userSpice.
Also may I say that the header is echoed back regardless of what the parser.php is doing. Even if I comment out db->insert and $fields I'm stuck with that.
But there is one more interesting thing. If I access parser.php directly, the echo does show correct. Only 0 is echoed back (or 1 if the db->insert is successful).
Regards,
Jakob
Example
$.post('parser.php', {
post_var1:var1,
post_var2:var
},
function(data)
{
console.log("Response: "+data);
});
then in the parser.php I submit this data to db. So I need to include init.php, header.php and securePage in the parser.
Example
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/users/init.php';
require_once $abs_us_root.$us_url_root.'users/includes/header.php';
if (!securePage($_SERVER['PHP_SELF'])){die();}
if($f_var1 = $_POST['post_var1'] ) $fields[var1] = $f_var1;
if($f_var2 = $_POST['post_var2'] ) $fields[var2] = $f_var2;
$success = $db->insert('devices',$fields);
if(success) echo "1";
else echo "0";
?>
This should be pretty straight forward right?
Well the problem is that when I get echo from parser.php, the console.log prints the whole header (users/includes/header.php) + my echo 0 or 1.
I tryed to flush() and ob_flush() and then echo with no success. Problem occurs when I include header.php. If header.php is not included, the echo works OK. But then I'm stuck without DB class...
I also searched header.php and not found any of the echo routines. Also header.php is still original userSpice.
Also may I say that the header is echoed back regardless of what the parser.php is doing. Even if I comment out db->insert and $fields I'm stuck with that.
But there is one more interesting thing. If I access parser.php directly, the echo does show correct. Only 0 is echoed back (or 1 if the db->insert is successful).
Regards,
Jakob