PHP - Php Above The Root
Hi guys,
I've got a simple script that I'm running from a folder above the root (as a cron job). I've tried the script in the httpdocs folder and it works fine. Code: [Select] mail('email@example.com', 'Before include', '', 'From:<email@example.com>'); // include the myriad class include($_SERVER['DOCUMENT_ROOT'].'/path/to/class'); mail('email@example.com', 'After include', '', 'From:<email@example.com>'); // initiate and instance of our class $obj = new class_name; $email = $obj->email; $file = $obj->file_name; mail('email@example.com', 'End of file', $email.' & '.$file, 'From:<email@example.com>'); If I run this file in httpdocs, it's fine and I get all emails. If I run this from 1 folder above the root (from a cron job), I get the first 2 emails but not the last one, suggesting that the include hasn't worked. Could this be a permissions problem? I have tried running the cron job as both root and apache and changed the owner/group of the script to match. Is there a reason why includes won't work above the root? Similar TutorialsIf I an deep inside of nested folders, how do I get back to the Web Root (as far as directory notation goes)?? Debbie Having problems pointing to where files are. Is this the root?: Code: [Select] include "../connectdb.php"; That file is locate din the root. If I am already in the root when I include that statment, the file isn't found. If I use the above code while I am in the subdirectory hello, (root/hello), it works. I use this in every page, so I think I need a way to point to the absolute root, not relative. Hi, I have a dynamic variable like this: /def/g/qaz/pol/cxz/cba/abc I only wish to keep this: /def/g/qaz/pol/cxz How would I do this? Thanks, - mme is there a way in php to link from the root dir ? like in html you just use the '/' at the start for the link " <a herf="/link.php" ></a> " but i noticed this does not work when using php like include or require. so is there anywey to tell a link to start from root dir? without using the ../../link.php I have been getting a lot more client requests to protect files. What is the easiest way to do this. So, basically I have tried doing it outside the public directory. There are too many things that cause issues with this. I haven't been able to get a successfull implementation of this since I started working with this. So I was thinking instead about password protecting a directory that is inside public view, but still get files via PHP. Is there a way to setup a password protected directory, then retreive stuff from that directory using PHP. Or, a good way to put them outside the public folder. Everything I have tried to do to get a file to save outside of public view, has not worked. It always says uploaded but the file is never there. Also, I have verified correct permission for this as well. Hi All, I googled this and there is endless results. I went through a lot of them but couldn't get this working properly. How do I link from within my web site root to files outside the root? It works for me using relative links i.e. ../../phpfiles/includes but that is going to get messy and I can't get a way of doing absolute links to work. If someone could lay that out so a newbie can get it clearly I would really appreciate it! Also - I understand why I should put all of my php files outside the web root but is this a guaranteed way to secure these files other than someone hacking my ftp access? I've looked at a few site hierarchy examples - Am I right that the only pages within the web site root should be template pages with calls to required files (outside the root), session checks, and content includes and all other includes that have php executable code should be outside the root? I really appreciate the advice and insight. Thank you! Hi, I want to get root path and use on links even if i'm in sub to sub folder etc... suppose my site name is fitness.com and having two subfolder. so url will become http://www.fitness.com/dir/dir_sub here i want to put a link to go to root directory file. there are different ways to do that. e.g: Code: [Select] <a href='../../filename.php'>go to that page</a> but i want to use some constant that always shows to root directory. as i defined here Code: [Select] define("SERVER_NAME" , $_SERVER['HTTP_HOST']); //and used it like this <a href='<?php echo SERVER_NAME; ?>/filename.php'>go to that page</a> it works when we're on root directory. but when we go to sub directory it added sub directory name with it. which i don't want. is there any way? Thanks hey guys im still having a issue with using the root path when requiring external files. So i can use one path and never have to worry about this issue. require("/functions/function_battle.php"); the file is located here Code: [Select] C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php i dont understand (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') im suppose to be including the php folder or something? Code: [Select] Fatal error: require() [function.require]: Failed opening required '/functions/function_battle.php' (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') in C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php on line 2 Because I have include files in a subdirectory called "incl", I cannot rely on using relative paths because that include file is in a header on and the pages are in multiple subdirectories (or in the root). I need some way to get the location of the root (the one where my index file is located). I want to use something like this: $path= $_SERVER['DOCUMENT_ROOT']; include $path."/subdirectory/file.php"; However, when I use $_SERVER['DOCUMENT_ROOT'] I get : /home/content/j/p/f/name55/html/ which is not where the index file sits. Any ideas on how to get the directory where my index file sits? (i.e. the index that gets read when you got to www.domain.com) Hi Guys I am struggling with a shell_exec command in the long run, but I am trying to work down the root cause. The error I am getting with shell_exec is a file not found error, so I thought I would start with getting to the right folder. I have this Code: [Select] $sym_dir = "/root/"; $cwd = getcwd(); echo getcwd()."\n"; chdir ($sym_dir); echo getcwd()."\n"; Which in theory should 1st display '/var/www' as it does and then display the contents of root, at least that is my understanding! However my return is this /var/www /var/www Why cannot I move outside the web root? Cheers Dave I having been searching through the forum and other websites for information on reading a file (an image file) located above my root directory. I would like to store images outside the root directory and then use PHP to call those images for registered users. Basically I want to create a secure web gallery. I am using GoDaddy Deluxe shared hosting, and have managed to create a webroot directory and place files above it. I have found several scripts for reading files using the readfile() function, however when I actually implement the script to find the file and read its contents, it does not seem to find the file. I know my directory path is correct, as I can call an echo function inside a test.php file located in the same folder as the images (above my root). I would love some incite as to where I went wrong, or if there is a specific GoDaddy work around that needs to be implemented. Also, if I am going about this the wrong way, please let me know if there is a more effective way of going about this! Thank you so much! Hi guys, I am trying to retrieve some information from sessions. I have this in my header.php <?php if(isset($_SESSION['username'])){ $username = $_SESSION['username']; echo $username; } ?> Hey y'all.
I'll gladly admit that I'm not a server guy - I have the utmost respect for people comfortable enough with *nix to handle Apache setup and configuration in a production environment. I can noodle about in *nix typically without killing anything vitally important, but trust me when I say no-one wants me to be a server administrator. That having been said, I do have a development server behind my home network firewall running Ubuntu that I use to test and develop the sites that I create on my separate Windows box. So I try to keep up with the way a shared server would be set up in a real-world situation, to a degree. For instance, I haven't bothered setting up the mail server or FTP, but I do create virtual host files for each of my projects.
So, I've got a virtual host set up on the directory /var/www/myAwesomeSite.com/ with the .conf file containing the following configuration:
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName myAwesomeSite.com DocumentRoot /var/www/myAwesomeSite.com/www <Directory /var/www/myAwesomeSite.com/www> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>Now, in my php scripts echoing out $_SERVER['DOCUMENT_ROOT'] gives me 'myAwesomeSite/www' as I would expect. And using $_SERVER['DOCUMENT_ROOT'] in any require() statements actually does include the requested file, so that part seems to be working fine. My question is this: when I use a leading slash ('/'), shouldn't that equate to the document root? I use it at work all the time and it works flawlessly, but on the dev server I have set up here, it's a no-go. Is there another config command that I need to issue to make it work, or am I crazy? Basically, am I missing a setting somewhere that will make this: require_once('/path/to/my/include.php');work like this? require_once($_SERVER['DOCUMENT_ROOT'].'/to/my/include.php');*edit* I just realized that I used the wrong slash in the title of this post, but I don't see a way to change the topic title. crap. Edited by maxxd, 23 November 2014 - 11:20 AM. Hey guys. Basically i have a file containing Database connection information stored at the root of my site www.worldwidelighthouses.com/Lighthouses-Database-Connection-Information.php I want to be able to connect to it using pages such as www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Beachy-Head-Lighthouse.php and www.worldwidelighthouses.com/Lightships/Lightship1.php Obviously 1 is 1 directory down, one is 2 directories down. My server doesnt allow for include 'www.worldwidelighthouses.com/Lighthouses-Database-Connection-Information.php' So whats the best way to always find this file, no matter what directory i am in? Finding out how far away i am from the server root and adding ../ to the include for each folder down was my first idea. Is this best? Thanks, Danny. Hello! I was working on a simple url generator, but than i though to myself, why not put everything in the root. I've heard thats not a good idea, but i'm ot sure why. I can immagine it gets really messy when you have a lot of files, but its also easy, if you ask me. I was just wondering what your view on this is. What are the pros and what are the cons? Thanks I have a number of PHP helper scripts that are stored outside the root directory of my websites. Those scripts may be used by one or more of my websites. Let's say I have two websites Website A uses PHP 7.0 Website B uses PHP 7.3Will the helper scripts be potentially executed using different versions of PHP? In other words, if Website B calls a helper script using a require statement, does that helper script execute as PHP 7.3? But if Website A calls the script, it would be executed as PHP 7.0. Howdy,
So I am creating a website with SQLite and this time I decided to follow the rule of putting the SQLite DB outside of the document root. However, the admin would need to admin, basically, the DB, so I have two choices:
a) Put PhpLiteAdmin (The SQLite DB manager like PHPmyAdmin is for MySQL) in the document root while giving it a path to the actually DB that is outside of the document root;
b) Set a subdomain to a directory outside of the document root of course and put both PhpLiteAdmin and the SQLite DB there and the admin would access it like this - db.Awesome-Website.com;
Which one of those two options are safer?
Thank you very much!
I've been doing a lot of studying of Linux lately. I enabled the root acount to do some work. When done, even if I logout, close the terminal, or reboot, I can still access the root account without supplying the root password. So what am I not understanding or what am I doing wrong? I don't really need to disable the root account, but this is just a learning experience, and I'm not understanding why I still have access. See below:
# I needed to enable root access for something
skunkbad:~$ sudo passwd root
# I did what I needed to do
skunkbad:~$ sudo -i
root@ubuntu-Inspiron-3647:~#
# I logout from root
root@ubuntu-Inspiron-3647:~# logout
# I disable the root access per instructions from many internet references
skunkbad:~$ sudo passwd -dl root
# Root access is still available, even if I close and reopen the terminal
skunkbad:~$ sudo -i
# I logout from root
root@ubuntu-Inspiron-3647:~# logout
# Trying to access root via su prompts for password, and old password is wrong
skunkbad:~$ su
Password:
su: Authentication failure
So I just started watching the videos from Stanford, Google, MIT and a few on youtube. One of them contained the code for using tkinter function to create an application window and I tried to put the same type of thing together can anyone tell me what I am doing wrong cause nothing is happeing for me. I am running linux mint:
# - So this is what it feels like # - To be alive #!/user/bin/python import sys author = "Brian T. Flores" version = "0.1" sessionID = 0 #Get Interface from Tkinter import * #initialize interface root = Tk() #modify root window info root.title("Unknown Limits - Massive Multiplayer RPG") root.geometry("200x100") #initialize root window root.mainloop() #if session is > 0: #Get Player Info UserName = "Brian Flores" Password = "enterprise" rank = 32 #planetOverview planetName = "Earth" plasmaOnhand = 1000000000 titainiumOnhand = 340000 crystalOnhand = 55000000 magneticEnergyOnhand = 350000 ecosystem = "No" # yes or no depending on wars or natural disasters that could have damaged or destroyed your ecosystem if there is no ecosystem the atmosphere must be cleaned up and another must be transplanted from another world. ecosystemDamage = 10000; #Damage can result from experiments, wars, natural disasters. At 10,000 damage the ecosystem goes extinct. You can repair this damage my researching technologies and building machines to do such repair # else: # print "You are not logged in!"; # raw_input()Well for some reason it's not working. All I am doing here is setting some vars and using the root.tk function. If anyone has any Ideas or tips to get this basic script working let me know. Thank you, DaRedHead Edited by DaRedHead, 21 November 2014 - 09:17 PM. Hi guys, I am searching for the definitive way of obtaining the root directory of my app. I need to it to work on localhost and also on ALL platforms, NIX, Windows etc. I would like to do this as I wish to use it to locate all my sub directory files - includes, model etc. For example, I may have this as my landing page: http://www.mywebsite.com/index.php The root directory might be: html The index.php might reside he html/index.php ... but my includes files might be he html/lib/includes So I would be looking to obtain the root in an absolute kind of way to allow me to string together the includes sub directory in a relative kind of way. In summary then: 1. How to obtain the root with 100% percent success, all of the time on all platforms. 2. How to string the sub directory together with 100% percent success, all of the time on all platforms. 3. Any comments on this as an approach, also welcome. Many thanks in advance, S |