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 Quote Link to comment 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. Quote Link to comment 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); } //------------------------------------------- ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
trq Posted May 5, 2008 Share Posted May 5, 2008 Take a look at the curl extension. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.