dflow Posted November 2, 2011 Share Posted November 2, 2011 im trying to understand this Post Data script it's not posting, no errors: postdata.php <?php //create array of data to be posted //$post_data['firstName'] = 'Name'; $post_data['item_name'] = '12345'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //we also need to add a question mark at the beginning of the string $post_string = '?' . $post_string; //we are going to need the length of the data string $data_length = strlen($post_string); //let's open the connection $connection = fsockopen('www.example.com', 80); //sending the data fputs($connection, "POST /i.php HTTP/1.1\r\n"); fputs($connection, "Host: www.example.com \r\n"); fputs($connection, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($connection, "Content-Length: $data_length\r\n"); fputs($connection, "Connection: close\r\n\r\n"); fputs($connection, $post_string); //closing the connection fclose($connection); ?> reuslt should be posted here i.php <?php require('database_connection.php');?> <?php if(isset($post_items[0])) { //$Subscription_id = mysql_real_escape_string($md5c); //$PropertyID = mysql_real_escape_string($rowData['ID']); //$User_ID = mysql_real_escape_string($rowData['User_ID']); $item_name=mysql_real_escape_string($post_items[0]); $query = 'INSERT INTO SP_subscriptions(id,) values("'.$item_name.'")'; //$query = 'INSERT INTO SP_subscriptions(id,PropertyID,User_ID) values("'.$item_name.'","'.$PropertyID.'","'.$User_ID.'")'; $success = mysql_query($query); } else { $item_name=54321; $query = 'INSERT INTO SP_subscriptions(id) values('.$item_name.')'; //$query = 'INSERT INTO SP_subscriptions(id,PropertyID,User_ID) values("'.$item_name.'","'.$PropertyID.'","'.$User_ID.'")'; $success = mysql_query($query);} //var_dump($_POST); //var_dump($query); echo $query; ?> Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/ Share on other sites More sharing options...
joel24 Posted November 3, 2011 Share Posted November 3, 2011 you're not trying to fetch any posted records... if(isset($post_items[0])) { //should be $_POST['item_name'] since your script will be posting $_POST['item_name'] from your array if(isset($_POST['item_name'])) { //also try this so you get a grasp of what's being posted print_r($_POST); Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1284462 Share on other sites More sharing options...
dflow Posted November 3, 2011 Author Share Posted November 3, 2011 you're not trying to fetch any posted records... if(isset($post_items[0])) { //should be $_POST['item_name'] since your script will be posting $_POST['item_name'] from your array if(isset($_POST['item_name'])) { //also try this so you get a grasp of what's being posted print_r($_POST); tried that before i get nothing Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1284561 Share on other sites More sharing options...
joel24 Posted November 3, 2011 Share Posted November 3, 2011 have a read of this thread http://www.codingforums.com/showthread.php?t=160316 in short, the variables are stored in $GLOBALS['HTTP_RAW_POST_DATA']; rather than $_POST... try run this on the page receiving the data... [from the aforementioned thread & user 'kbluhm'] $raw_data = $GLOBALS['HTTP_RAW_POST_DATA']; parse_str( $raw_data, $_POST ); print_r( $_POST ); Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1284568 Share on other sites More sharing options...
dflow Posted November 15, 2011 Author Share Posted November 15, 2011 have a read of this thread http://www.codingforums.com/showthread.php?t=160316 in short, the variables are stored in $GLOBALS['HTTP_RAW_POST_DATA']; rather than $_POST... try run this on the page receiving the data... [from the aforementioned thread & user 'kbluhm'] $raw_data = $GLOBALS['HTTP_RAW_POST_DATA']; parse_str( $raw_data, $_POST ); print_r( $_POST ); cant figure this out Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1288344 Share on other sites More sharing options...
joel24 Posted November 16, 2011 Share Posted November 16, 2011 sorry I've never have to do this before - is your fsockopen acquiring a connection? someone else may have successfully achieved this before and be able to help... $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { //create array of data to be posted //$post_data['firstName'] = 'Name'; $post_data['item_name'] = '12345'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //we also need to add a question mark at the beginning of the string $post_string = '?' . $post_string; //we are going to need the length of the data string $data_length = strlen($post_string); //sending the data fputs($connection, "POST /i.php HTTP/1.1\r\n"); fputs($connection, "Host: www.example.com \r\n"); fputs($connection, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($connection, "Content-Length: $data_length\r\n"); fputs($connection, "Connection: close\r\n\r\n"); fputs($connection, $post_string); //closing the connection fclose($connection); } Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1288551 Share on other sites More sharing options...
dflow Posted November 17, 2011 Author Share Posted November 17, 2011 sorry I've never have to do this before - is your fsockopen acquiring a connection? someone else may have successfully achieved this before and be able to help... $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { //create array of data to be posted //$post_data['firstName'] = 'Name'; $post_data['item_name'] = '12345'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode() $post_string = implode ('&', $post_items); //we also need to add a question mark at the beginning of the string $post_string = '?' . $post_string; //we are going to need the length of the data string $data_length = strlen($post_string); //sending the data fputs($connection, "POST /i.php HTTP/1.1\r\n"); fputs($connection, "Host: www.example.com \r\n"); fputs($connection, "Content-Type: application/x-www-form-urlencoded\r\n"); fputs($connection, "Content-Length: $data_length\r\n"); fputs($connection, "Connection: close\r\n\r\n"); fputs($connection, $post_string); //closing the connection fclose($connection); } hi i actually found this tutorial but he is using OO and im getting mysqli() errors. here http://www.softcoded.com/articles/paypal_hack1.php but i dont get how he can with this code post in the redirect ? Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1289016 Share on other sites More sharing options...
joel24 Posted November 17, 2011 Share Posted November 17, 2011 change the mysqli to normal normal mysql queries... you'll obviously have to change some of the arguments you pass to the mysql function Link to comment https://forums.phpfreaks.com/topic/250336-post-data-help/#findComment-1289091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.