therealwesfoster Posted May 5, 2008 Share Posted May 5, 2008 How can I send POST data without using a form? For instance, when process.php loads, I want it to load an entry from the DB, and sent it to receive.php as a POST variable. Maybe it can be done with CURL, but I'm not familiar with that so idk. Suggestions, tips, tutorials.. anything is welcome. Thanks Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/ Share on other sites More sharing options...
Btown2 Posted May 5, 2008 Share Posted May 5, 2008 Based on my limited knowledge you cannot send a $_POST variable without a form, but you may want to look into the hidden input type to solve your problem. <input type=hidden name=data value='datayouwanttosend'> or you could set a temporary cookie to send the data, then once its recevied destroy the cookie. Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/#findComment-533153 Share on other sites More sharing options...
tronicsmasta Posted May 5, 2008 Share Posted May 5, 2008 I did find this on google... but not sure how to use it lol maybe one of the SR. guys can help out Answer : You can open an HTTP socket connection and send HTTP POST commands. Here is an example : <? // Generate the request header $ReqHeader = "POST $URI HTTP/1.1\n". "Host: $Host\n". "Content-Type: application/x-www-form-urlencoded\n". "Content-Length: $ContentLength\n\n". "$ReqBody\n"; // Open the connection to the host $socket = fsockopen($Host, 80, &$errno, &$errstr); if (!$socket) $Result["errno"] = $errno; $Result["errstr"] = $errstr; return $Result; } $idx = 0; fputs($socket, $ReqHeader); while (!feof($socket)) $Result[$idx++] = fgets($socket, 128); } //------------------------------------------- ?> Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/#findComment-533154 Share on other sites More sharing options...
therealwesfoster Posted May 5, 2008 Author Share Posted May 5, 2008 Hmm.. seems like it would work. I'll try it in just a sec. More suggestions welcome Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/#findComment-533161 Share on other sites More sharing options...
trq Posted May 5, 2008 Share Posted May 5, 2008 Take a look at the curl extension. Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/#findComment-533165 Share on other sites More sharing options...
therealwesfoster Posted May 5, 2008 Author Share Posted May 5, 2008 Take a look at the curl extension. Thanks, I have this now. <?php // Redirect $curl_session = @curl_init('./receive.php'); @curl_setopt($curl_session, CURLOPT_POST, 1); @curl_setopt($curl_session, CURLOPT_POSTFIELDS, "name=$username"); @curl_setopt($curl_session, CURLOPT_FOLLOWLOCATION, 1); $send = @curl_exec($curl_session); if (!send) { // well.. didnt work } ?> The code doesn't redirect properly... Any help? Wes Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/#findComment-533167 Share on other sites More sharing options...
therealwesfoster Posted May 5, 2008 Author Share Posted May 5, 2008 It seems that on process.php, it's just including the receive.php on its page? I might be taking this all wrong.. just thought I'd mention this Link to comment https://forums.phpfreaks.com/topic/104138-send-post-data-without-a-form/#findComment-533169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.