Results 1 to 6 of 6
  1. #1

    PHP: fsockopen Problem

    I am trying to make a PHP Script to send SMS using NowSMS, which would make use of "fsockopen", but before I do that, I wanted to check whether my computer can work with it, so I used this code:

    PHP Code:
    $page "/index.php";
    $fp fsockopen("$host"80, &$errno, &$errdesc30);
    if ( ! 
    $fp )
    { die ( 
    "Couldn't connect to $host:\nError: $errno\nDesc: $errdesc\n" ); }

    $request "GET $page HTTP/1.0\r\n";
    $request .= "Host: $host\r\n";
    $request .= "Connection: Close";
    fputs $fp$request );
    while ( ! 
    feof$fp ) )
    $page[] = fgets$fp1024 ); }
    fclose$fp );print "the server returned ".(count($page))." lines!";
    Which returned errors like this:

    Warning: fsockopen(): php_network_getaddresses: gethostbyname failed in test.php on line 4
    Warning: fsockopen(): unable to connect to h**p:// in test.php on line 4
    Couldn't connect to h**p:// Error: 0 Desc: The operation completed successfully.
    The problem may lie on the PHP.INI or PHP installation, but I don't know what. Since I have also tried accessing Google (which is accessible via normal means of an Internet browser) with this script but the script returned the same error message too (but this time it failed to connect to Maybe it's not my Apache's problem because if it is, the script must have been able to connect to Google. If not the PHP, maybe the problem lies in my network configuration or DNS, which I have no idea of how to set.

    I am using Windows XP Home Edition SP1, PHP 4.3.8 and Apache 2.0.50.

    Sorry for the h**p because the forum won't let me post URLs before I reach 5 posts.

  2. #2
    Join Date
    May 2005
    i have a feeling that its ur host that prevents the use of fsock. Most people disable the use of fsock including me, it can cause very big problem when exploited ....

    i suggest u request from your host (or even yourself) to enable fsock if you really need it.....If I remember correctly, being in safe mode can also cause this problem, so turn off safe mode if you're in it........ gd luck.. lol

  3. #3
    Then how can I enable fsock in my own localhost? I will use this for my internal company SMS server which is cut off from the Internet so I think it will be quite safe to enable it in this matter. Besides, all other NowSMS users are also using the fsockopen method, so I think it should be no problem.

  4. #4
    Join Date
    Dec 2001
    NYC, NY
    try using curl.. if your php install has it configed in.. its a lot easier to use that to post data then fsockopen
    Blog your life away

  5. #5
    Yes I have enabled Curl in my configuration but it's confusing to use.
    Can you help me to convert the code above to Curl?

    The actual script which will be used for SMS doesn't differ much from the above, the only difference will be in the $page variable and the contents of $request and how the data will be retrieved. I will be using GET here, not POST, because NowSMS mainly supports GET functions.

  6. #6
    Join Date
    May 2005
    I guess you can find a online converter around the web .... go to google and search for php to curl converters... I ever converted php to asp using a convert before =) Good luck... i cant help you with the link becux not at home now

Posting Permissions

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