
|
View Full Version : Getting the path of a dir.
UrlGuy 04-08-2005, 11:47 PM Hi,
I was wondering if anyone know of a command that would output the local dir the script is in?
Like; /home/user/public_html/directory/
AND
only showing the path at public_html or below
like; /home/user/public_html/
or
/home/user/
Is there any PHP commands or so I could have used to find for example a file there?
Because I do password logging with my files, and I want it in a unreadable directory like /home/user/ where it cant be read from public, and I dont want each user to specify the location, but rather get the script to do this for them.
Anyone know how I could do this?
Thanks in advance:)
Dylanz0r 04-09-2005, 01:07 AM Totally lost me there mate. I dont quite get your question?
Something like "echo $ARGV[0]/.."?
getenv("SCRIPT_FILENAME");
Sorry, im slightly lost..
insanelymacintosh 04-09-2005, 02:14 AM I'm with Dylanzor on this one. I understand what you want (i think) but I don't quite understand what you are trying to do with it. Can you go into a little more detail of what you are trying to do?
UrlGuy 04-09-2005, 03:19 AM Ok, thanks for replies ppl.
What I want to do is,
Lets say I log all IP's that's been visiting my page,
As this logfile needs to be written to, it need chmod permission 0777 - All permissions.
Therefore I would not like it in a public accessible directory, but rather a folder like /home/user/ where the public can not view it.
But I do not want to specify this path, (neither do I know how to) so I need some PHP command to find this directory itself.
The /home/username/pulic_html/
Like the users root dir
and/or the /home/user/ directory
(As on Cpanel)
I need to know how PHP could find this directory $domain_base or something, and how/where to specify it
Hope you understood a lil more now, and srry for my poor english =|
insanelymacintosh 04-09-2005, 03:42 AM No problems on the poor English. Can you tell us if you programmed this logfile script or did you download it from somewhere? If you downloaded it, then what site did you get it from? or what is the name of it?
UrlGuy 04-09-2005, 05:17 AM hehe, the logging is quite simple, although I didnt make that either, someone here on the boards helped me with that and the code looks something like;
------------------------------------------
$filename = 'users.html';
$postarray = array($first_name, $last_name, $alt_email, $email, $password, $ip, $time);
$content = implode(",", $postarray);
$somecontent = "$content\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
------------------------------------------
Only problem is, I do not want this file "users.html" to be stored in the same directory as the form, as anyone could view it.
I have tried the chmod() command, but its very many people who have servers which dont support this command, and I would therefore like to store the logs in an unreadable directory.
orbitz 04-09-2005, 05:22 AM Originally posted by UrlGuy
[B]Hi,
I was wondering if anyone know of a command that would output the local dir the script is in?
Like; /home/user/public_html/directory/
you can use this
$_SERVER['SCRIPT_FILENAME']
UrlGuy 04-09-2005, 05:42 AM thanks, think it might work! But I am not 100% sure as I seem to not be able to echo it to see if it works, and what directory it gives, gives me a error (...parse error, unexpected T_ECHO in /home/url/public_html/test.php...)
Heres the test script I tried:
<?php
$location_of_self = $_SERVER['test.php']
echo $location_of_self;
?>
So I guess this would output the current directory which the script "test.php" (as used above) resides in, but how would I get the /home/url/public_html/ directory?
(I would actually only need the username part, as all who use this script are on cPanel and have the public_html directory, but a full dir. would be nice)
So if this script worx, how could I echo it, if possible?
And this gives me the current directory which the script resides in, right? How would I get the domain root directory?
Thanks again for all your helpful replies people!
Regards,
orbitz 04-09-2005, 05:54 AM you missed the ";" on the first line
and do not change 'SCRIPT_FILENAME' to your filename, leave it as it is
try this line:
<?php
$path=explode("test.php",$_SERVER['SCRIPT_FILENAME']);
echo $path[0];
?>
save your file as test.php
UrlGuy 04-09-2005, 06:03 AM Hey thanks!!
It worked!!
It finally shows me /home/username/public_html/ as output.
One more thing, is there any way I could just have /home/username/ outputted?
I make this script, where I log passwords and so, which I want to place in a unreadable directory like /home/username/.
Regards,
orbitz 04-09-2005, 06:08 AM you can change test.php to public_html/
<?php
$path=explode("public_html/",$_SERVER['SCRIPT_FILENAME']);
echo $path[0];
?>
UrlGuy 04-09-2005, 07:22 AM it worked!
thanks again man!!
UrlGuy 04-09-2005, 07:53 AM Stumbled across another error when setting this up, really hope anyone can help me solve this.
I use this code in my config.php (which I have included in all my files):
<?php
$self=explode("public_html/",$_SERVER['SCRIPT_FILENAME']);
echo $self[0];
?>
To get the file "admin.html" which is located at the unreadable directory /home/ownt/admin.html I do this inclusion in admin.php:
include("$self;admin.html");
Which then brings me this long error;
/home/ownt/ /home/ownt/
Warning: main(Array;admin.html): failed to open stream: No such file or directory in /home/ownt/public_html/ffhtest/admin.php on line 12
Warning: main(Array;admin.html): failed to open stream: No such file or directory in /home/ownt/public_html/ffhtest/admin.php on line 12
Warning: main(): Failed opening 'Array;admin.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ownt/public_html/ffhtest/admin.php on line 12
So for some reason, it now output "Array;" instead of the path I wanted, weird.. :S
X-TechMedia 04-09-2005, 09:07 AM try include($self[0]."admin.html");
UrlGuy 04-09-2005, 09:13 AM Originally posted by X-TechMedia
try include($self[0]."admin.html");
Thanks!! It worked!!
PHP is cool once its working hehe =D
Thanks to everyone who has replied, I owe you big and would never made this without you! :)
|