How to find the cpanel username for a website?

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
tommytx123
php-forum Active User
php-forum Active User
Posts: 35
Joined: Sat Sep 19, 2015 4:57 pm

Wed Sep 15, 2021 10:09 am

This could be in any language but since i am using it in a php program hoped i could ask it here..
I have written a php script that needs the username in the url like this... /home/myusername/public_htm/mydirectory/myfile.php... and this script needs to call for myusername a dozen times during a run..
i have be setting $myusername = "myusername" at the top of the script, but I want to deploy this script into any site.. so I have searched everywhere... mysql options.. and other places and cannot find the user name.

Does anyone know where in a basic website the username is stored? Its easy to find the username for the frontend admin section by searching mysql.. but the username is usually the same username that is used for accessing the cpanel...

If anyone has any idea what i could call tograb the username i would really appreciate it..
Any clues? Thanks.
AdoptiveSolution
php-forum GURU
php-forum GURU
Posts: 217
Joined: Wed Jun 15, 2016 8:35 am

Sun Sep 19, 2021 4:05 am

Here’s code that shows all the variables of your server.
What you need is the pathname.
No need to remember the cpanel name.

Put the code in a php file and save it anywhere on your server.
Then open the webpage in the browser.

Code: Select all

<style>

code {color: red;}

</style>

<hr>

<p>done met xml (@php_uname)</p>

<hr>

<?php

echo "Hostname (n) : <code>" . @php_uname(n) . "</code><br />\n";

if (function_exists( 'shell_exec' )) {
	echo "Hostname : <code>" . @gethostbyname(trim(`hostname`)) . "</code><br />\n";
}
else {
	echo "Server IP : <code>". $_SERVER['SERVER_ADDR'] . "</code><br />\n";
}
echo "Platform (s) : <code>" . @php_uname(s) . "</code>, (r) : <code>" . @php_uname(r) . "</code>, (v) : <code>" . @php_uname(v) . "</code><br />\n";
echo "Architecture (m) : <code>" . @php_uname(m) . "</code><br />\n";
echo "Username : <code>" . get_current_user () . "</code> ( UiD: <code>" . getmyuid() . "</code>, GiD: <code>" . getmygid() . "</code> )<br />\n";
echo "Curent Path (getcwd) : <code>" . getcwd () . "</code><br />\n";
echo "--FILE-- : <code>" . __FILE__ . "</code><br />\n";
echo "dirname FILE : <code>" . dirname(__FILE__) . "</code><br />\n";
echo "basename FILE : <code>" . basename(__FILE__) . "</code><br />\n";
echo "dirname SCRIPT_NAME : <code>" . dirname($_SERVER["SCRIPT_NAME"]) . "</code><br />\n";
echo "basename SCRIPT_NAME : <code>" . basename($_SERVER["SCRIPT_NAME"]) . "</code><br />\n";
echo "<hr>";

$path_parts = pathinfo(__FILE__);

echo '$path_parts = <code>pathinfo(__FILE__)</code><br />' . "\n";

echo '$path_parts[' . "'dirname']'" . "<br />\n";

echo "dirname : <code>" . $path_parts['dirname'], "</code><br />\n";
echo "basename : <code>" . $path_parts['basename'], "</code><br />\n";
echo "extension : <code>" . $path_parts['extension'], "</code><br />\n";
echo "filename : <code>" . $path_parts['filename'], "</code><br />\n"; // since PHP 5.2.0

echo "<hr>";

echo '<p>All names have prefix <b>$_SERVER["name"]</b></p>';

echo "USER                           " . " : <code>" . $_SERVER["USER"] . "</code><br />\n";
echo "HOME                           " . " : <code>" . $_SERVER["HOME"] . "</code><br />\n";
echo "FCGI_ROLE                      " . " : <code>" . $_SERVER["FCGI_ROLE"] . "</code><br />\n";
echo "REDIRECT_MOD_X_SENDFILE_ENABLED" . " : <code>" . $_SERVER["REDIRECT_MOD_X_SENDFILE_ENABLED"] . "</code><br />\n";

echo "REDIRECT_HANDLER               " . " : <code>" . $_SERVER["REDIRECT_HANDLER"] . "</code><br />\n";
echo "REDIRECT_STATUS                " . " : <code>" . $_SERVER["REDIRECT_STATUS"] . "</code><br />\n";

echo "MOD_X_SENDFILE_ENABLED         " . " : <code>" . $_SERVER["MOD_X_SENDFILE_ENABLED"] . "</code><br />\n";
echo "HTTP_HOST                      " . " : <code>" . $_SERVER["HTTP_HOST"] . "</code><br />\n";

echo "HTTP_USER_AGENT                " . " : <code>" . $_SERVER["HTTP_USER_AGENT"] . "</code><br />\n";
echo "HTTP_ACCEPT                    " . " : <code>" . $_SERVER["HTTP_ACCEPT"] . "</code><br />\n";

echo "HTTP_ACCEPT_LANGUAGE           " . " : <code>" . $_SERVER["HTTP_ACCEPT_LANGUAGE"] . "</code><br />\n";
echo "HTTP_ACCEPT_ENCODING           " . " : <code>" . $_SERVER["HTTP_ACCEPT_ENCODING"] . "</code><br />\n";

echo "HTTP_CONNECTION                " . " : <code>" . $_SERVER["HTTP_CONNECTION"] . "</code><br />\n";
echo "PATH                           " . " : <code>" . $_SERVER["PATH"] . "</code><br />\n";

echo "SERVER_SIGNATURE               " . " : <code>" . $_SERVER["SERVER_SIGNATURE"] . "</code><br />\n";
echo "SERVER_SOFTWARE                " . " : <code>" . $_SERVER["SERVER_SOFTWARE"] . "</code><br />\n";

echo "SERVER_NAME                    " . " : <code>" . $_SERVER["SERVER_NAME"] . "</code><br />\n";
$ip_server = $_SERVER["SERVER_ADDR"];

if (!filter_var($ip_server, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
    $ip_server_echo = "is a valid IPv6 address";
} elseif (!filter_var($ip_server, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
    $ip_server_echo = "is a valid IPv4 address";
}
echo "SERVER_ADDR                    " . " : <code>" . $_SERVER["SERVER_ADDR"] . "</code> $ip_server_echo<br />\n";
echo "SERVER_PORT                    " . " : <code>" . $_SERVER["SERVER_PORT"] . "</code><br />\n";

$ip_remote = $_SERVER["REMOTE_ADDR"];

if (!filter_var($ip_remote, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
    $ip_remote_echo = "is a valid IPv6 address";
} elseif (!filter_var($ip_remote, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
    $ip_remote_echo = "is a valid IPv4 address";
}
echo "REMOTE_ADDR                    " . " : <code>" . $_SERVER["REMOTE_ADDR"] . "</code> $ip_remote_echo<br />\n";

echo "DOCUMENT_ROOT                  " . " : <code>" . $_SERVER["DOCUMENT_ROOT"] . "</code><br />\n";
echo "SERVER_ADMIN                   " . " : <code>" . $_SERVER["SERVER_ADMIN"] . "</code><br />\n";

echo "SCRIPT_FILENAME                " . " : <code>" . $_SERVER["SCRIPT_FILENAME"] . "</code><br />\n";
echo "REMOTE_PORT                    " . " : <code>" . $_SERVER["REMOTE_PORT"] . "</code><br />\n";

echo "REDIRECT_URL                   " . " : <code>" . $_SERVER["REDIRECT_URL"] . "</code><br />\n";
echo "GATEWAY_INTERFACE              " . " : <code>" . $_SERVER["GATEWAY_INTERFACE"] . "</code><br />\n";

echo "SERVER_PROTOCOL                " . " : <code>" . $_SERVER["SERVER_PROTOCOL"] . "</code><br />\n";
echo "REQUEST_METHOD                 " . " : <code>" . $_SERVER["REQUEST_METHOD"] . "</code><br />\n";

echo "QUERY_STRING                   " . " : <code>" . $_SERVER["QUERY_STRING"] . "</code><br />\n";
echo "REQUEST_URI                    " . " : <code>" . $_SERVER["REQUEST_URI"] . "</code><br />\n";

echo "SCRIPT_NAME                    " . " : <code>" . $_SERVER["SCRIPT_NAME"] . "</code><br />\n";
echo "ORIG_SCRIPT_FILENAME           " . " : <code>" . $_SERVER["ORIG_SCRIPT_FILENAME"] . "</code><br />\n";

echo "ORIG_PATH_INFO                 " . " : <code>" . $_SERVER["ORIG_PATH_INFO"] . "</code><br />\n";
echo "ORIG_PATH_TRANSLATED           " . " : <code>" . $_SERVER["ORIG_PATH_TRANSLATED"] . "</code><br />\n";

echo "ORIG_SCRIPT_NAME               " . " : <code>" . $_SERVER["ORIG_SCRIPT_NAME"] . "</code><br />\n";
echo "PHP_SELF                       " . " : <code>" . $_SERVER["PHP_SELF"] . "</code><br />\n";

echo "REQUEST_TIME_FLOAT             " . " : <code>" . $_SERVER["REQUEST_TIME_FLOAT"] . "</code><br />\n";
echo "REQUEST_TIME                   " . " : <code>" . $_SERVER["REQUEST_TIME"] . "</code><br />\n";

?>
Post Reply