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