PHP - What Version Of Php Does Code Stored Outside The Root Use
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. Similar TutorialsHow can I run php code that is stored in a database? I have my pages created by grabbing the contents of a pageBody mySQL table cell, but some pages require further php to be able to display correctly. For example, I have a players page, which will list all players, and some information about them. The players and information is all saved in a players table in my database (separate to the pages table where pageBody is stored). I use simple php to grab all the players and format all of their information so it can be displayed on the page. This is the flow of information that I would like: User clicks on players page browser loads content page (this is a template page), and grabs the pageid from $_GET browser then reads pages table in database to get the pageBody associated with the pageid The pageBody will contain more php, which will run the players script to retrieve the list, and display Doing it the above way will make it much easier to extend the website to include more types of pages that has to run additional php scripts. The only way I can think of this working is by doing this: user clicks on players page browser loads content page, grabs pageid from $_GET browser checks the pageid for the one associated with players (hard coded into the php script) browser then loads the players.php script instead of going to the database This above way means that I will need to edit the index.php page everytime I add a new list type (example, coaches, volunteers etc). Anyone have any suggestions? I know my question is long, but I was finding it hard to explain it in an easy to understand way, but I'm still not sure if I have :S. Cheers Denno Hi! I was wondering if there is a way to execute php code which is stored in mysql database using php. At the minute I am using a echo to try and run php code stored in a mysql database but this just displays the code and does not run the php code. Thanks for any help! Hi all, But of a PHP newbie so treat me nice but this one is driving me nuts I have the exact same login.php file running on two different servers and they have slightly different versions of PHP installed as follows: 1. PHP Version 5.0.4 - version http://www.trafficpaymaster.com/tpm/phpversion.php 2. PHP Version 5.2.15 - version http://www.dentistsinflorida.org/tpm/phpversion.php The login works fine on the first server from he http://www.trafficpaymaster.com/tpm/login.php Email: test@test.com Pwd: test But try it on the second server he http://www.dentistsinflorida.org/tpm/login.php Using the same email and password (which is correct) it just loops round not letting the user into the main script at index.php Question: Why? What have I got wrong for that later version of PHP? Many thanks guys. wrote a stored procedure this morning and i don’t know how to get the values out of it through a class function in php or phpmyadmin. here is what i wrote : public function totalProcedures($friend_name,$session_id) { /* *query to fetch stored procedure */ try { //executing the stored procedure $sql_sp="CALL timeline (:friend, :session,@updates, @group_posts)"; $stmt_sp= $this->_db->prepare($sql_sp); $stmt_sp->bindValue(":friend",$friend_name); $stmt_sp->bindValue(":session",$session_id); $stmt_sp->execute(); $rows=$stmt_sp->fetch(PDO::FETCH_ASSOC); $stmt_sp->closeCursor(); // closing the stored procedure //trying to get values from OUT parameters. $stmt_sp_2=$this->_db->prepare("select @updates,@group_posts"); $stmt_sp_2->execute(); return $stmt_sp_2->fetch(PDO::FETCH_ASSOC); } catch (PDOException $ei) { echo $ei->getMessage(); } } can someone helpme how to get results. here is the storedprocedu DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeline`(IN `friend` VARCHAR(255), IN `session_id` VARCHAR(255), OUT `updates` VARCHAR(62555), OUT `group_posts` VARCHAR(62555)) BEGIN select * FROM updates where author in (friend,session_id) order by time desc limit 5; select * FROM group_posts where author_gp in (friend,session_id) order by pdate desc limit 5; END$$ DELIMITER ; i get the result in php myadmin as follows:
how do i do this inside a php class function. CALL timeline('shan2batman','aboutthecreator', @updates, @group_posts);
If I an deep inside of nested folders, how do I get back to the Web Root (as far as directory notation goes)?? Debbie 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? 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. 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 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 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 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 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! 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 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; } ?> 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 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! 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 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. 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. |