Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?????

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    wow

    thanks...... it works


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •