[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Pass form value from PHP page to ASP.Net

Posted on 2008-11-13
3
Medium Priority
?
397 Views
Last Modified: 2012-05-05
Hi,
A Customer has a site developed in PHP and hosting on a remote server with a basic form.  I need to have some of this data posted to a different web site on a second server running an ASP.net site.

I discounted cookie / session values and cant use query string values in the URI due to the length and contents of the data.

Any suggestions?
0
Comment
Question by:Molior
  • 2
2 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22952950
Yes, you can use POST to send the data.  Show us what you've tried so far, and I'll try to find an example of a POST from one page to another. ~Ray
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 22953138
Sample showing how to configure headers and post array.  HTH, ~Ray
<?php // RAY_cross_post.php
 
// URL OF THE WEB SITE WE WANT TO POST TO
$url	= "www.yoursite.com";
 
// SCRIPT OF THE WEB SITE WE WANT TO POST TO
$scr	= "/process.asp";
 
 
 
 
// PUT UP OUR FORM TO COLLECT SOME DATA
if (empty($_POST)) { ?>
Enter Something Here:
<form action="<?=$PHP_SELF?>" method="post">
<input type="text" name="my_field_1" />
<input type="text" name="my_field_2" />
<input type="submit" name="_submit" value="Go!">
</form>
<?php die(); }
 
 
 
// READ MY POST DATA, ADD OR DELETE ANY NEEDED FIELDS
$postdata	= '';
$req		= 'cmd=yes'; // THIS IS ARBITRARY - ADDED TO ALL INPUT DATA
foreach ($_POST as $key => $value) {
	$postdata	.= "\n $key = $value ";			// SAVE THE COLLECTION FOR LATER USE
	if (substr($key,0,1) == '_') continue;			// ARBITRARY - OMIT ALL FIELDS STARTING WITH UNDERSCORE
	$value		= urlencode(stripslashes($value));	// ENCODE FOR CROSS POST
	$req		.= "&$key=$value";			// APPEND TO THE CROSS-POST STRING
}
 
// POST TO OUR CHOSEN WEB SITE AND SCRIPT
$header .= "POST $scr 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 ($url, 80, $errno, $errstr, 30);
 
 
// TEST FOR SUCCESSFUL POST OPEN
if (!$fp) { // HTTP ERROR PROCESSING
	die("HTTP ERROR fsockopen failed \n\n URL=$url \n\n SCR=$scr \n\n ERRNO=$errno \n\n ERRSTR=$errstr \n\n");
}
 
// HTTP OPEN - WRITE HEADER AND REQUEST
fputs ($fp, $header . $req);
 
// HTTP OPEN - READ SCRIPT RESPONSE, IF ANY
$script_reply 	= '';
$script_headers	= '';
while (!feof($fp)) {
	$script_reply	= fgets ($fp, 1024);
	$script_headers	.= $script_reply;
}
fclose ($fp);
 
// IF NEEDED, PROCESS THE INFORMATION FROM THE OTHER WEB SITE
var_dump($script_headers);
var_dump($script_reply);

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 dynamically set the form action using jQuery.
Suggested Courses

591 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