Jump to content

Post Data help


dflow

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

  • 2 weeks later...

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.