Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-04-2009, 12:29 PM   PM User | #1
build
New to the CF scene

 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
build is an unknown quantity at this point
Post data to another server

Hi all,

it is possible to post value data into another server?
server A -------->> server B
the data that i want to post is :
Name: John Doe
Address : 123 example

code from server A : http://serverA.com/post.php
PHP Code:
<?

$url 
"http://www.serverA.com/post.php";
$Name="John Doe";
$Address="123 example";
$postdata "Name=$Name&Address=$Address";
$useragent"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" ;

$ch curl_init();
//set some cookie details up (depending on the site)
curl_setopt($chCURLOPT_COOKIEJAR"cookies.txt");
curl_setopt($chCURLOPT_COOKIEFILE"cookies.txt");
curl_setopt($chCURLOPT_USERAGENT$useragent); //set our user agent
curl_setopt($chCURLOPT_POST1); //set how many paramaters
curl_setopt($chCURLOPT_URL,$url); //set the url we want to use
curl_setopt($chCURLOPT_POSTFIELDS,$postdata); //set data to post


$resultcurl_exec ($ch); //execute and get the results
curl_close ($ch); 
print 
$result//display the reuslt 

?>
Code server B to get the result: http://serverB.com/get.php

PHP Code:
<?php 
ini_set 
("display_errors""1"); 
error_reporting(E_ALL); 

$Name =$_GET["Name"]; 
$Address=$_GET["Address"];
$postdata $_GET["postdata"]; 

$curlopt=
Name = $Name \n 
Address = $Address \n 
"
;

print 
$name;
print 
$Address;
Print 
$postdata;
?>

Notice: Undefined index: Name in /home/cybeszw7/public_html/get.php on line 4
Notice: Undefined index: Address in /home/cybeszw7/public_html/get.php on line 5
Notice: Undefined variable: postdata in /home/cybeszw7/public_html/get.php on line 6

the variable that post from server cannt read in server B
what should i do to write in server A and Server B?????
build is offline   Reply With Quote
Old 03-04-2009, 01:37 PM   PM User | #2
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,229
Thanks: 2
Thanked 190 Times in 188 Posts
djm0219 is on a distinguished road
PHP Code:
<?

$url 
"http://www.serverA.com/post.php";
$postdata['Name'] = "John Doe";
$postdata['Address'] ="123 example";
$useragent"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" ;

$ch curl_init();
//set some cookie details up (depending on the site)
curl_setopt($chCURLOPT_COOKIEJAR"cookies.txt");
curl_setopt($chCURLOPT_COOKIEFILE"cookies.txt");
curl_setopt($chCURLOPT_USERAGENT$useragent); //set our user agent
curl_setopt($chCURLOPT_POST1); //set how many paramaters
curl_setopt($chCURLOPT_URL,$url); //set the url we want to use
curl_setopt($chCURLOPT_POSTFIELDS,$postdata); //set data to post


$resultcurl_exec ($ch); //execute and get the results
curl_close ($ch); 
print 
$result//display the reuslt 

?>
PHP Code:
<?php 
ini_set 
("display_errors""1"); 
error_reporting(E_ALL); 

$Name $_POST['Name']; 
$Address$_POST['Address'];

print 
$Name;
print 
$Address;

?>
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 03-04-2009, 01:49 PM   PM User | #3
build
New to the CF scene

 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
build is an unknown quantity at this point
wow

thanks...... it works
build is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:42 AM.


Advertisement
Log in to turn off these ads.