doni49 Posted October 21, 2006 Share Posted October 21, 2006 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 accessif ($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 Falseecho nl2br($response);fclose($socket);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24622-problem-with-fgets/ Share on other sites More sharing options...
doni49 Posted October 21, 2006 Author Share Posted October 21, 2006 This is all that gets sent to the browser when I load this script (I did View Source):[code]Resource id #2<br>False[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24622-problem-with-fgets/#findComment-112301 Share on other sites More sharing options...
doni49 Posted October 22, 2006 Author Share Posted October 22, 2006 Ok, I just figured out WHY it wasn't working. I wasn't appending the response value. So once the while loop ended the response variable was empty. Quote Link to comment https://forums.phpfreaks.com/topic/24622-problem-with-fgets/#findComment-112524 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.