Jump to content

How to Detect it is public_html or httpdocs?


fbemo

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :o

 

What do you mean it supposedly read $host url? What does $host contain?

Link to comment
Share on other sites

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 :o

 

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.

Link to comment
Share on other sites

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 :o

 

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.

Link to comment
Share on other sites

Yes, that's the thing I'm trying to do now but no luck at all.  :confused:

 

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.

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.