Php Script That I Was Aksed To Make.
Caboose
title = name(self, handle) Join Date: 2003-02-15 Member: 13597Members, Constellation

in Off-Topic
<div class="IPBDescription">For school.</div> Well, I don't really know PHP, but I am the teacher assistant for Mr. Powell the Comp Sci teacher. Anyway, he asked me to write him a php script and I told him I didn't know Php, well... I know the basic syntax of PHP, I just don't know most of the commands...
Anyway... I need a script that will go intop the /home directory on the comp sci server and use the finger command on the user names, then make a list of the users's real names as reported by finger and for those names to link to the /home/user/public_html directory.
I'm reading up on it, but since I'ma total noob at PHP, where else do I come? Ot forums, that's rite <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html//emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
If anyone would help me out here, I'd appreciate it a lot. <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html//emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
Anyway... I need a script that will go intop the /home directory on the comp sci server and use the finger command on the user names, then make a list of the users's real names as reported by finger and for those names to link to the /home/user/public_html directory.
I'm reading up on it, but since I'ma total noob at PHP, where else do I come? Ot forums, that's rite <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html//emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
If anyone would help me out here, I'd appreciate it a lot. <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html//emoticons/smile-fix.gif' border='0' style='vertical-align:middle' alt='smile-fix.gif' /><!--endemo-->
Comments
$delim = "Name:"; // May differ for different versions of "finger". This is the string directly before the data you want to extract.
$directory = "/home"; // Self Explanatory
$realnames = array();
$usernames = array();
if (!$dir = opendir($directory))
{
echo "Error opening directory $directory.";
}
else
{
while ($currentfile = readdir($dir))
{
if (is_dir($directory . "/" . $currentfile) && ($currentfile != ".") && ($currentfile != "..") && (substr($currentfile,0,1) != "."))
{
$usernames[] = $currentfile;
}
}
}
foreach ($usernames as $user)
{
$name = exec("finger {$user} | grep {$delim}");
$name = substr($name,strpos($name,$delim) + strlen($delim) + 1);
$realnames[] = $name;
echo $name;
}
?><!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
That works with the most recent version of finger available for Gentoo. It should work no matter what the output, if configured properly.
Edit: woops, that just gets the real names. I'll add the linkage, one moment.