-1

I need to find the absolute path of my site in the same way that php outputs it if I run the file directly with the following code in the root of my site:

<?php

echo realpath(dirname(__FILE__));

?>

Problem is, I have .htpasswd implemented for security reasons, but I have the wrong full path in there and need to get to find out the full path by other means...

So, if there is a .htaccess way of maybe putting in the full path of my site into the URL Address, or outputting it directly within the .htaccess login box, that would be great... so that I can fix this in the .htpasswd file.

Any ideas? I don't want to remove the password login for even a second as it is needed for huge security implications. How can I do this by another means?

Here is the contents of my .htpasswd file:

htpasswd -c /home/before_publichtmldir/.htpasswd user
New password: PASSWORD
Re-type new password: PASSWORD
Adding password for username user

So, my username = user and password = PASSWORD

But typing this in keeps popping up the dialog and never accepts it as the correct username and password.

# Require popup dialog for access
AuthType Basic
AuthName "You must give a password"
AuthUserFile /home/before_publichtmldir/.htpasswd
Require valid-user

But no matter what I put in here it continuously loops the Dialog asking for my username and password again. So, my conclusion is that the path must be wrong here.

Also, does .htaccess and .htpasswd have to be within the same directory for this to work?

Solomon Closson
  • 6,111
  • 14
  • 73
  • 115
  • by definition, .htaccess can only affect requests to the directory that the .htaccess file is in, and any sub-directories. To edit the htaccess means you'd have to be IN the directory that contains your site. – Marc B Jan 19 '14 at 05:11
  • Yes, I know this... But I do not know the full path... it is different! – Solomon Closson Jan 19 '14 at 05:12
  • so how do you plan to add something to the htaccess if you don't know where it is? – Marc B Jan 19 '14 at 05:12
  • I know what folder it is in... I do not know the absolute path and/or what drive it is in – Solomon Closson Jan 19 '14 at 05:13
  • then start with the server conf files, e.g. httpd.conf, or wherever your site's `` is defined. it'll have the document root of the site there. – Marc B Jan 19 '14 at 05:14
  • I think you are misunderstanding me... I have access to the folder where .htaccess is in. I do not have access to any folders above that. I need to know the absolute folderpath of where it is. – Solomon Closson Jan 19 '14 at 05:14
  • what kind of access? ftp/ssh? there'd be "pwd" to tell you the current full directory. – Marc B Jan 19 '14 at 05:15
  • Thanks for your help. I got it working finally. Seems they have to be within the same root and I changed it to a `md5` hash of the password and than it worked. Cheers :) – Solomon Closson Jan 19 '14 at 06:14

1 Answers1

0

Try using

$_SERVER['DOCUMENT_ROOT']
rjv
  • 6,058
  • 5
  • 27
  • 49