shell exec - How to use the function shell_exec() PHP
Get the solution ↓↓↓I have a problem with the function shell_exec(), i've tried everything but I don't know where is the problem. I have this php program that verificates if you are logg in or not, I wanted to use a cookie but i'm not allowed in the apache server of the company where i'm working I don't know why. So normally in this program I check if I have already initiated my session, if I don't, I use a login that the user put it in a case of text in the page before, if I do (already initiated my session), I'll use the login that I put in the case of text before, now stocked in the session variable. I don't know if its the right way to do but thats the solution that I came with. I'm not an expert in php. So the problem is that the function shell_exec() works outside the first "if"but not in the condition, when I get into the condition its returns me nothing. I would like to know your opinions.
This is the code:
$login = $_POST['login_venezia'];
if (isset($login))
{
$log = $login;
if($_SESSION['login_test']!=NULL)
{
$tableau = shell_exec('groups'.$_SESSION['login']);
echo "1";
echo $_SESSION['login']."\n";
}
else
{
$tableau = shell_exec('groups'.$log);
echo "2";
echo "Login = ".$log;
}
//$tableau = shell_exec('groups '.$log);
echo "Login = ".$login;
echo "Tableau = ".$tableau;
$resultat = explode(" ",$tableau);
$cookies = $_COOKIE['session_ser'];
die;
$path = dirname($_SERVER['PHP_SELF']); //chemin avant de fichier courant
$path_separe = explode('/',$path); //nous retourne la chaine de caractere donc le chemin du fichier mais sans les slash
$lenght = count($path_separe);
$imp = $path_separe[$lenght-2];
if($tableau != NULL)
{
for($i=0; $i<count($resultat);$i++)
{
if($resultat[$i] === $imp && $cookies!=NULL)
{
$valeur = 1;
}
}
if($i === count($resultat))
{
//header('Location: verifnon.php?mavar=1'); //n'appartien pas au projet
}
}
else
{
//header('Location: compteinexistant.php?mavar=1'); //son compte existe pas
echo "Erreur";
}
if($valeur === 1)
{
session_cache_limiter('private');
$cache_limiter = session_cache_limiter();
/* Configure le dГ©lai d'expiration Г 30 minutes */
session_cache_expire(1440);
$cache_expire = session_cache_expire();
session_start();
$_SESSION['login'] = $login;
//header('Location: verifoui.php?mavar=1');
}
}
else
{
echo "Veuillez saisir votre login \n";
}
Answer
Solution:
Put a space after groups otherwise you are running 'groupslogin' which is not a command:
if($_SESSION['login_test']!=NULL)
{
$tableau = shell_exec('groups '.$_SESSION['login']);
echo "1";
echo $_SESSION['login']."\n";
}
else
{
$tableau = shell_exec('groups '.$log);
echo "2";
echo "Login = ".$log;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: sqlstate[hy000] [1698] access denied for user 'root'@'localhost'
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.