Jump to content

Problem with fgets


doni49

Recommended Posts

I have a web hosting account with CPanel access.  I'm trying to create a script that will login to cpanel, perform certain actions and then read the output that CPanel creates as a result of my actions.  This script DOES perform the action that it's supposed to do but doesn't receive any of the output.

I've got 2 debugging lines in the code (noted for reference below).  They indicate that Socket does have the resource value but response is empty.

Thanks.

[code]
<?php
$cpuser = "myUsername"; // Username used to login to CPanel
$cppass = "myPassword"; // Password used to login to CPanel
$domain = "mydomain.com"; // Domain name where CPanel is run
$skin = "mySkin"; // Set to cPanel skin you use (script won't work if it doesn't match)

// Info required for cPanel access
if ($secure) {
  $url = "ssl://".$domain;
  $port = 2083;
} else {
  $url = $domain;
  $port = 2082;
}
$socket = fsockopen($url,$port);
if (!$socket) { echo "Failed to open socket connection... Bailing out!\n"; exit; }


// Encode authentication string
$authstr = $cpuser.":".$cppass;
$pass = base64_encode($authstr);

// Make POST to cPanel
//The "URL" variable used below DOES get set properly--I've tested and confirmed that.  I just don't want to display that publicly.
fputs($socket,$url . " HTTP/1.0\r\n");
fputs($socket,"Host: $domain\r\n");
fputs($socket,"Authorization: Basic $pass\r\n");
fputs($socket,"Connection: Close\r\n");
fputs($socket,"\r\n");

if($socket){echo $socket . "<br>";}//                <====== This line shows "Resource id #2"


// Grab response even if we don't do anything with it.
while (!feof($socket)) {
  $response = fgets($socket,4096);
  if ($debug) {echo $response;}
}
if($response){echo "True";}else{echo "False";}//      <====== This line shows False
echo nl2br($response);

fclose($socket);
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/24622-problem-with-fgets/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.