Solved

Sending HTTP POST thru fsockopen?

Posted on 2011-03-23
2
372 Views
Last Modified: 2012-05-11
The task seems simple. I want to use fsockopen to post variables to another page.

Just to give you an idea how I want it to work... This is being used for adding user accounts into two separate databases on different websites. The user fills out a form, the $_POST variables are used to create a user account in the main database, then I want to send those variables to another page (through fsocket) to setup the account on the secondary databse.

Here's what I have so far (I will provide all pieces that I'm using for testing):

The Form:
<form action="testprocess.php" method="post">
First Name: <input type="text" name="first_name" size="20"><br /><br />
Last Name: <input type="text" name="last_name" size="20"><br /><br />
<input type="submit" value="Submit">
</form>

Open in new window



Main Processing Script  "testprocess.php"
<?
$first_name = urlencode($_POST['first_name']);
$last_name = urlencode($_POST['last_name']);

// Here would be all my functions that I want my script to do before sending the post variables to the other web site. 

$req = "first_name=".$first_name;
$req .= "&last_name=".$last_name;

// post back to PayPal system to validate
$header .= "POST /insertacct.php HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('demo.mysite.com', 80, $errno, $errstr, 30);
fputs ($fp, $header . $req);
fclose ($fp);

header("location: test.php?chk=1");
?>

Open in new window



Insert Account Page
(this is the "behind-the-scenes" page that will be on a different website)
<?
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];

  mysql_query(" INSERT INTO `users`  (`last_name` , `first_name`)  VALUES ('$last_name','$first_name')") or die(mysql_error());
?>

Open in new window




The address of my script would be:
http://ecafe.mydomain.com/insertacct.php
Hopefully, it doesn't matter that it is a Subdomain.

0
Comment
Question by:tonyhhisc
2 Comments
 
LVL 3

Accepted Solution

by:
WebCricket earned 500 total points
ID: 35200437
If you want to use fsocket open, I would use this script http://www.php.net/manual/en/function.fsockopen.php#101872 but I highly recommend using cURL for this sort of operation. CURL can handle all the heavy lifting for you.
0
 

Author Closing Comment

by:tonyhhisc
ID: 35210445
Thanks I used CURL
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql sentence 2 13
remove border from element 5 16
php connect() failed error 25 17
Programatically extract date from website 8 20
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now