Jump to content

Recommended Posts

Hi,

 

Given the file ClientHttpRequest.php (code given below), and given that it will be accessed as such from a web browser from multiple clients:

 

http://<host name>/ClientHttpRequest.php?url=<some url>&port=443&arg1=somearg&arg2=somearg&arg3=somearg&path=/test.php&svr=<my server>

 

Is the following ClientHttpRequest code thread safe? (Please note the last line of the code which is instantiating the class and calling the public method in the same line.)

 

Thanks.

 

------------------------

 

<?php

 

class ClientHttpRequest {

public function __construct() {

}

 

public function post() {

$host = $_GET['url'];

$port = $_GET['port'];

$req = "arg1=" . $_GET['arg1'] . "&arg2=" . $_GET['arg2'] . "&arg3=" . $_GET['arg3'];

$http = "POST " . $_GET['path'] . " HTTP/1.1\r\n";

$http .= "Host: " . $_GET['svr'] . "\r\n";

$http .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";

$http .= "Content-Type: application/x-www-form-urlencoded\r\n";

$http .= "Content-Length: " . strlen($req) . "\r\n";

$http .= "Connection: close\r\n\r\n";

$http .= $req . "\r\n\r\n";

 

$fp = fsockopen ($host, $port, $errno, $errstr, 30);

 

if (!$fp) {

echo "Could not open a socket to host";

} else {

// NO HTTP ERROR

fputs($fp, $http);

 

// Get final acknowledgement

while (!feof($fp)) {

$res .= fgets ($fp, 1024);

}

fclose ($fp);

print $res;

}

}

}

 

(new ClientHttpRequest())->post();

?>

Link to comment
https://forums.phpfreaks.com/topic/166377-noob-question/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.