fbemo Posted December 24, 2009 Share Posted December 24, 2009 How to check whether it is cPanel or Plesk? If it found public_html perform <?php include("callcPanel.php"); ?> Else if found httpdocs perform <?php include("callPlesk.php"); ?> Else exit; *cPanel is using public_html while Plesk is using httpdocs Anyone knows? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 Haven't tested this code that I wrote, but it's not hard. $docRoot = getenv("DOCUMENT_ROOT"); if (preg_match('/public_html/i', $docRoot)) { include("callcPanel.php"); } elseif (preg_match('/httpdocs/i', $docRoot) { include("callPlesk.php"); } else { exit(); } So you know, DOCUMENT_ROOT returns something like.. " /usr/local/apache/share/htdocs" preg_match is a good function to match something from it. EDIT:'ed a few things Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 Haven't tested this code that I wrote, but it's not hard. $docRoot = getenv("DOCUMENT_ROOT"); if (preg_match('/public_html/i', $docRoot)) { include("callcPanel.php"); } elseif (preg_match('/httpdocs/i', $docRoot) { include("callPlesk.php"); } else { exit(); } So you know, DOCUMENT_ROOT returns something like.. " /usr/local/apache/share/htdocs" preg_match is a good function to match something from it. EDIT:'ed a few things I'm sorry I don't get it what is /i and getnv for? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 Haven't tested this code that I wrote, but it's not hard. $docRoot = getenv("DOCUMENT_ROOT"); if (preg_match('/public_html/i', $docRoot)) { include("callcPanel.php"); } elseif (preg_match('/httpdocs/i', $docRoot) { include("callPlesk.php"); } else { exit(); } So you know, DOCUMENT_ROOT returns something like.. " /usr/local/apache/share/htdocs" preg_match is a good function to match something from it. EDIT:'ed a few things I'm sorry I don't get it what is /i and getnv for? $_SERVER is a superglobal of getenv. /i is a modifier to make the case insensitive. So it can be "PUBLIC_HTML" or "public_html", It's usually just safer that way. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 Parse error: syntax error, unexpected on line 43 which means; } elseif (preg_match('/httpdocs/i', $docRoot) { <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnect($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Couldn\'t connet to '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Couldn\'t connet to '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpClose($conn) { //close ftp connection ftp_close($conn); } //----------- end of functions ------------------------- //get the credentials from user $user = $_POST['username']; //change to ftp username $username = $pass = $_POST['passwd']; //change to ftp password $host = $_POST['urlname']; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnect($host,$user,$pass); $docRoot = getenv("DOCUMENT_ROOT"); if (preg_match('/public_html/i', $docRoot)) { include("callcPanel.php"); } elseif (preg_match('/httpdocs/i', $docRoot) { include("callPlesk.php"); } else { exit(); } //close ftp connection ftpClose($conn); } ?> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 Parse error: syntax error, unexpected on line 43 which means;[...] Whoops, Forgot to encase the elseif in brackets. Replace it with this line: } elseif (preg_match('/httpdocs/i', $docRoot)) { And it should work. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 You are rocks man! It is working, silly me... simple sytnax error... btw I still get a problem: Fatal error: Cannot redeclare ftpconnect() (previously declared in /home/------/public_html/exampleofsite.com/upload.php:7) in /home/------/public_html/exampleofsite.com/callcPanel.php on line 15 I think I've ftp close it before calling it... Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 You are rocks man! It is working, silly me... simple sytnax error... btw I still get a problem: Fatal error: Cannot redeclare ftpconnect() (previously declared in /home/------/public_html/exampleofsite.com/upload.php:7) in /home/------/public_html/exampleofsite.com/callcPanel.php on line 15 I think I've ftp close it before calling it... Might be. Look in upload.php line 7 and callcPanel.php line 15, You'd usually get that sort of error on an eval() or include() if they use the same declarations when instantiated.. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 Ok I've change the function name, but there was a problem uploading the files... It working if I runs the callPlesk.php or callcPanel.php by without bypassing upload.php (the call function). And another problem I just found, it don't read public_html, Create Folders Sorry the folder: httpdocs/images already exists There's no such httpdocs inside public_html/cPanel Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 If run this for Plesk which it has httpdocs, but it still call callcPanel.php it seems just a slight problem... but I just can't figure it out for now.. <?php error_reporting(E_ALL ^ E_WARNING); //------------- functions //--------------------------- connect and login to server function ftpconnectA($host,$user,$pass) { global $conn; $conn=ftp_connect($host) or die('Couldn\'t connet to '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'); //login to server if (!ftp_login($conn,$user,$pass)) { echo 'Couldn\'t connet to '.$host.'.<br /><a href="javascript:history.back(-1)">Back</a>'; exit; } } //-------------------------- close ftp connections function ftpCloseA($conn) { //close ftp connection ftp_close($conn); } //----------- end of functions ------------------------- //get the credentials from user $user = $_POST['username']; //change to ftp username $username = $pass = $_POST['passwd']; //change to ftp password $host = $_POST['urlname']; //change to ftp url if (($user == "") || ($pass == "") || ($host == "")) { echo "Please fill all the details."; } else { //connect to server ftpconnectA($host,$user,$pass); $docRoot = getenv("DOCUMENT_ROOT"); if (preg_match('/public_html/i', $docRoot)) { include("callcPanel.php"); } elseif (preg_match('/httpdocs/i', $docRoot)) { include("callPlesk.php"); } else { exit(); } //close ftp connection ftpCloseA($conn); } ?> Quote Link to comment Share on other sites More sharing options...
Adam Posted December 24, 2009 Share Posted December 24, 2009 preg_match is a good function to match something from it. Think preg_match() is a little over kill for simple text matching. strpos() would be the better, light-weight solution here. For example: if (strpos($docRoot, 'public_html') !== false) { ---- If run this for Plesk which it has httpdocs, but it still call callcPanel.php it seems just a slight problem... but I just can't figure it out for now.. Try var_dumping the $docRoot variable to check the value is what you expect. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 I think the code is not right, I try to echo it and get result; "$docRoot is reads for where this script is running", supposedly it read $host url. How do I going to manipulate this? Sorry, this might be a dumb question... I'm just too noob.. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 I try to echo it and get result; "$docRoot is reads for where this script is running", supposedly it read $host url. That's not what var_dump should show What do you mean it supposedly read $host url? What does $host contain? Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 24, 2009 Author Share Posted December 24, 2009 I try to echo it and get result; "$docRoot is reads for where this script is running", supposedly it read $host url. That's not what var_dump should show What do you mean it supposedly read $host url? What does $host contain? $host contain user URL, my website is providing free web templates for them. So they have to enter username,pass,url to get the template to be uploaded to their hosting. Thar's why I need to determine whether they are using cPanel or Plesk. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 I try to echo it and get result; "$docRoot is reads for where this script is running", supposedly it read $host url. That's not what var_dump should show What do you mean it supposedly read $host url? What does $host contain? $host contain user URL, my website is providing free web templates for them. So they have to enter username,pass,url to get the template to be uploaded to their hosting. Thar's why I need to determine whether they are using cPanel or Plesk. Oh.. The code you asked for to check the document root, will check yours not theirs, that's why it's always cpanel. I'm not sure how you use the FTP commands, but you have to scan their directories, you'll have to ditch the "getenv('DOCUMENT_ROOT')" part. Quote Link to comment Share on other sites More sharing options...
fbemo Posted December 25, 2009 Author Share Posted December 25, 2009 Yes, that's the thing I'm trying to do now but no luck at all. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 25, 2009 Share Posted December 25, 2009 Yes, that's the thing I'm trying to do now but no luck at all. Well using FTP are you able to list the directories and load them into your script? You can still easily parse and read what panel they need if you can do so, using the same code. Quote Link to comment 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.