PHP - Include Path Issue
Hello Everyone, i am fairly new in PHP coding, and facing some issue with include function in php. my problem is as follows:
in a php script which is located at "/include/cart.php" i am including a html page "cart_add.html" which is at location "/cart_add.html" now whenever i am clicking on any links on this page "cart_add.html" browser looking for all other pages at location "/include/" instead of "/" so in the browser i see url as "http://localhost/include/index.html" instead of "http://localhost/index.html" so i get error like this : [an error occurred while processing this directive] The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please help me to resolve this issue. Thanks very much Similar TutorialsDear Sir,
I am building a small framework and going to check on my local computer by using "XAMPP Server" so i have 2 folder and 5 file the hierarchy is:
- inc
- config.php (Contains all configuration of website like, Directory Separator, Include Path .. etc.)
- autoload.php
-classes
- Url.php (Class)
- Core.php (Class)
- index.php
when i try to run this application i got following Error:
Warning: require_once(Core.php): failed to open stream: No such file or directory in C:\xampp\htdocs\completed\inc\autoload.php on line 7 Fatal error: require_once(): Failed opening required 'Core.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\completed\inc\autoload.php on line 7 I have also tried to change settings of include_path php.ini changes are following: 1. remove ',;' from include_path 2. try to change to this '\php\PEAR' 3. put ';' in starting og php_include_path my current default setting of php include is: ;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; In the file "secure/checkout.php" I have... Code: [Select] <?php require_once "../config.inc.php"; ?> which is Relative. Can I use an Absolute Path instead?? Debbie Hi all, i was trying to include a php file in an index file into another files and those included file is including one file also. But for some reason the database connection file is not included. this is the map structure www/index.php <---- the file that uses include www/newsletter/newsletter.php <---- has a form with action process.php www/newsletter/process.php <--- this has an include referring to database.php www/newsletter/database.php <--- the databasefile This is what i did but it gives a server error in index.php include('newsletter/newsletter.php'); innewsletter.php <form action="newsletter/process.php" method="post"><!--- some form stuff--></form> in process.php include('database.php'); I really don't understand why it doesn't work and it's giving a server error 500. The form loads like it should in the index.php but the rest doesn't any help is appreciated. Hi! So I'm working for someone, and they want me to fix this error in a PHP file.. Here is the code: <?php include_once('config.php'); $online = mysql_query("SELECT * FROM bots WHERE status LIKE 'Online'"); $offline = mysql_query("SELECT * FROM bots WHERE status LIKE 'Offline'"); $dead = mysql_query("SELECT * FROM bots WHERE status LIKE 'Dead'"); $admintrue = mysql_query("SELECT * FROM bots WHERE admin LIKE 'True'"); $adminfalse = mysql_query("SELECT * FROM bots WHERE admin LIKE 'False'"); $windows8 = mysql_query("SELECT * FROM bots WHERE so LIKE '%8%'"); $windows7 = mysql_query("SELECT * FROM bots WHERE so LIKE '%7%'"); $windowsvista = mysql_query("SELECT * FROM bots WHERE so LIKE '%vista%'"); $windowsxp = mysql_query("SELECT * FROM bots WHERE so LIKE '%xp%'"); $unknown = mysql_query("SELECT * FROM bots WHERE so LIKE 'Unknown'"); $totalbots = mysql_num_rows(mysql_query("SELECT * FROM bots")); $onlinecount = 0; $offlinecount = 0; $deadcount = 0; $admintruecount = 0; $adminfalsecount = 0; $windows8count = 0; $windows7count = 0; $windowsvistacount = 0; $windowsxpcount = 0; $unknowncount = 0; while($row = mysql_fetch_array($online)){ $onlinecount++; } while($row = mysql_fetch_array($offline)){ $offlinecount++; } while($row = mysql_fetch_array($dead)){ $deadcount++; } while($row = mysql_fetch_array($admintrue)){ $admintruecount++; } while($row = mysql_fetch_array($adminfalse)){ $adminfalsecount++; } while($row = mysql_fetch_array($windows8)){ $windows8count++; } while($row = mysql_fetch_array($windows7)){ $windows7count++; } while($row = mysql_fetch_array($windowsvista)){ $windowsvistacount++; } while($row = mysql_fetch_array($windowsxp)){ $windowsxpcount++; } while($row = mysql_fetch_array($unknown)){ $unknowncount++; } $statustotal = $onlinecount + $offlinecount + $deadcount; $admintotal = $admintruecount + $adminfalsecount; $sototal = $windows7count + $windowsvistacount + $windowsxpcount + $unknowncount; ?> Can anyone tell me the error here, can how to fix it? Can I use this path? I didn't know if I could pull in images into a subdomain from another domain ../mysite.com/assets/img/avatars/defaultuser.jpg I'm getting the error below when I run my script on my remote server. I'm providing a relative path to this file and it works on my local server (XAMPP). I've researched it a bit and I think it has to do with how I indicate the path to the file on the remote server. I don't know what to do about it, however. I hope someone can help me. The file is in the indicated directory on the remote server and there are no permissions issues that I am aware of. The mystery phrase is: include_path='.:/opt/cpanel/ea-php73/root/usr/share/pear'
--Kenoli Warning: require(bootstrap/start.php): failed to open stream: No such file or directory in /home4/ournight/public_html/tio-new/__classes/pi_admin.php on line 3 Warning: require(bootstrap/start.php): failed to open stream: No such file or directory in /home4/ournight/public_html/tio-new/__classes/pi_admin.php on line 3 Fatal error: require(): Failed opening required 'bootstrap/start.php' (include_path='.:/opt/cpanel/ea-php73/root/usr/share/pear') in /home4/ournight/public_html/tio-new/__classes/pi_admin.php on line 3
Hey if you could help me I would really appreciate it, I haven't been coding for a while and I'm getting stuck on quite a basic part of my script, in fact it was the first part. I'm using the include(); function to include a file which will be used to show multiple pages through the $_GET variable, for example if you don't understand what I'm talking about if I was making an "about" page I might do index.php?page=about and it would retrieve the "about" page. Unfortunately I keep getting this error: Quote Warning: include(back_func.php?id=new) [function.include]: failed to open stream: No error in C:\Program Files\EasyPHP-5.3.9\www\link_extension\index.php on line 25 Warning: include() [function.include]: Failed opening 'back_func.php?id=new' for inclusion (include_path='.;C:\php\pear') in C:\Program Files\EasyPHP-5.3.9\www\link_extension\index.php on line 25 Notice: Undefined variable: var in C:\Program Files\EasyPHP-5.3.9\www\link_extension\index.php on line 26 This is the PHP in my index page, notice it consists of one line because I removed the rest for testing: Code: [Select] include('back_func.php?id=new'); echo $var;This is my back_func.php page, also simplified for testing: Code: [Select] <?php if (isset($_GET['id'])) $var = 'worked'; else $var = 'not'; ?> If you don't understand what I'm asking but feel you could help I'm happy to further explain, I'm expecting it's something basic I've forgotten. Thanks. Hi: 1.I have some scripts in a dir of my root directory that i wanted to move to a subdir in it . 2.So i created a dir "Set1" and moved them there. 3.Now each of these files has an include at the top which contains db info and another which contains session info etc). 4.After redirecting to the new location I modified the include as under and got errors - as listed below. 5.It appears that when a script in the new location is to be processed, it cannot find the db info. 6.It searches for the db info in the subdir and not in the main dir. I tried fiddling with the ../ stuff but havent succeeded. Any pointers please ? Many thanks:Swati ========================= /www/NEW contains connectionlink.php loglink.php /www/NEW/Set1 contains hr.php The header of hr.php is as under : <? header("Cache-Control: public"); include ("../NEW/connectionlink.php"); //db info include ("../NEW/loglink.php"); //loginfo ?> Errors that come up are as under. Lines 5, 6 of hr.php have the include statements: Code: [Select] Warning: include(../NEW/connectionlink.php) [function.include]: failed to open stream: No such file or directory in /home/tern/public_html/NEW/Set1/hr.php on line 5 Warning: include(../NEW/connectionlink.php) [function.include]: failed to open stream: No such file or directory in /home/tern/public_html/NEW/Set1/hr.php on line 5 Warning: include() [function.include]: Failed opening '../NEW/connectionlink.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/tern/public_html/NEW/Set1/hr.php on line 5 Warning: include(../NEW/loglink.php) [function.include]: failed to open stream: No such file or directory in /home/tern/public_html/NEW/Set1/hr.php on line 6 Warning: include(../NEW/loglink.php) [function.include]: failed to open stream: No such file or directory in /home/tern/public_html/NEW/Set1/hr.php on line 6 Warning: include() [function.include]: Failed opening '../NEW/loglink.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/tern/public_html/NEW/Set1/hr.php on line 6 Sorry, Please login and use this page I just installed this new script here http://webhost.pro/domain-check.php it's a basic domain availability tool. I am trying to make a form that can be used on any page forward to this page with the content. The page loads with this in the url webhost.pro/domain-check.php?domain=dwhs.net and will run the page. So I can make a form that just submits to that page and sends the details. I made this page for testing http://webhost.pro/test.html But no go, here is the code: <form id="search" action="/domain-check.php" method="GET"> <input type="text" name="s"> <a onClick="document.getElementById('search').submit()" class="button1">Search</a> <div class="clear"></div> </form> Thanks! Hi y'all. I just inherited a legacy system that is in mid-rebuild but needs to be tended until it can be completely phased out and have run into an issue I can't remember how to deal with. The file system is as such: DocumentRoot/ m/ js/ css/ In the 'm' directory I have many files that use require_once as so: require_once "m/another_file.php"; The problem is that none of them have a $_SERVER['DOCUMENT_ROOT'] or even a __DIR__ to start the path, so I'm blowing up with errors. I know this code works as it's currently in production, but I can't remember for the life of me what php.ini or .htaccess setting needs to be set to make it viable. My coworker swears he didn't have to do any magic to make it work on his system. Anybody old enough to remember? Edited June 25, 2020 by maxxdI think this is a simple question, but I'm just starting out and can't figure out how to do this exactly. I'm making a demo site for a flower shop. The structure is as such (only listing the particular files in question - once this is done, the rest will be easy) index.php -> inc_show_colors.php -> showColors.php The index is to be standard through the site, loading include files into a main content area. Clicking on a link loads inc_by_color.php (index.php -> index.php?page=by_color ) From there, one of the four colors is selected. showColors.php contains switch statements for each color. I want to load showColors.php into the main content window when a color is selected, and I need to have it work for all four colors. I'm not sure how to do this, as you can't pass a variable to an include from what I understand. What's the easiest way to go about this? Keep in mind this is an intro class and "best practices" are not necessary yet, just the simplest solution to get it working. I want each of these colors to link to another include file, which will load in its place in index.php. index.php: Code: [Select] <div id="maincontent"> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'by_color': include('includes/inc_by_color.php'); break; case 'by_type': include('includes/inc_by_type.php'); break; case 'by_occasion': include('includes/inc_by_occasion.php'); break; case 'view_cart': include('includes/inc_view_cart.php'); break; case 'payment_options': include('includes/inc_payment_options.php'); break; case 'home_page': default: include('includes/inc_home.php'); break; } } else include('includes/inc_home.php'); ?> </div> inc_by_color.php: The first link I tried doing in the way I thought would work, but it doesn't. It can't find the include file. The second one works, kind of - but it just loads the page by itself, not into the maincontent div in index.php. Code: [Select] <h1>Flowers Categorized by Color</h1> <div class="picdivcontainer"> <div class="picdiv"><a href="index.php?page=red"><img src="images/image.png" width="90" height="90" alt="Red Flowers" /> <p>Red</a></p></div> <div class="picdiv"><a href="showColors.php?color=white"><img src="images/image.png" width="90" height="90" alt="White Flowers" /></a> <p><a href="showColors.php?color=white">White</a></p></div> </div> and showColors.php: Code: [Select] if (isset($_GET['color'])) { switch ($_GET['color']) { case 'red': $result = mysql_query("SELECT * FROM flowers WHERE color='red'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { // Set and trim strings and show the resulting flowers from query $flowername = $row['name']; $flowerimage = $row['image']; $image_path = "images/"; $flowername = str_replace('_', ' ', $flowername); $flowername = ucwords($flowername); ?> <div class="picdiv"><p><?php echo $flowername."<br />"; $flowerimage = str_replace(' ', '_', $flowerimage); echo "<img src='images/" . $row['image'] . "' />"; ?></p></div> <?php } break; I realize that showColors.php is probably a really messy way of doing this, but I just need to get it functioning ASAP for now. CanI put one INCLUDE statement INSIDE of another INCLUDE statement? Hi Guys.. Merry Christmas Im kinda new to this fantastic world of PHP and i have a little problem i hope you can help me with. Im trying to build a website where I use include() to genereate my content. On my index.php i have a menu which includes content in a content div from external .php pages, my structure kinda goes like this.. (simplified) site/ index.php content/ fronpage.php products.php contact.php The HTML looks like this. <div id="menu"> <ul> <li><a href="index.php?page=frontpage">frontpage</a></li> <li><a href="index.php?page=products">frontpage</a></li> <li><a href="index.php?page=contact">frontpage</a></li> </ul> </div <div id="main"> <?php include('/content/'.$_GET['page'].'.php'); ?> </div> This all works very fine, but my problem is, can I have a include inside an already included page? I would like to have a menu on my products.php site, but that page is already included from above, and i would like the menu on the products.php site to stay as the content from the nested include changes with input from the /products folder. my idea was something like this. site/ index.php content/ frontpage.php products.php contact.php products/ product1.php product2.php the HTML on the index.php is the same as above and then i would add the include() on the products.php page, so its kinda the same thing, but one inside the other. HTML inside the products.php folder <div id="sub_menu"> <ul> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> <li><a href="#">frontpage</a></li> </ul> </div <div id="sub_main"> <?php include('/content/products'.$_GET['#'].'.php'); ?> </div> I dont know how to link to the new files so they will be included while the first include still stays on the page. Any of you know how and if this can be done? Or maybe at better way to do it? Hope this made sense, my first PHP question Thanks Hi Still a new comer when it comes to PHP. I have a situation where I want to use an include within an include and I am having trouble with my file paths. My main header include, includes everything for each page of my site, beyond the opening of the body to incorporate my navigation etc conditionally loading in css, and loading in titles and meta data etc depending on the page in question. This header needs to reference another include called the-pod.php which is required for every page, the only trouble is I want to use / to reference the root of the server and this is breaking my code. I can't use ../../ etc as its a different path depending on where the master file is located. So my question is how do I get around this? Can the root of the server or path to the root be stored in a variable? and if so how would I write this. Any tips / advice will be greatly appreciated. Hi guys, Happy New Year http://www.phpfreaks.com/forums/php-coding-help/?action=post How can i get the path http://www.phpfreaks.com/forums thanks, Directory structu /home/~test/public_html/soap/ .../xml/ .../bin/ .../products/browser/ In file /home/~test/public_html/soap/bin/products/browser/test.php, I include another file and call it's function: Code: [Select] require("../../xml/processXML.php"); $xmlData = generateXML(....); In the /home/~test/public_html/soap/xml/processXML.php, I have the following code: Code: [Select] function generateXML() { exec("../bin/code.cur"); } The problem is the exec("../bin/code.cur") fails of the relative path issue. I did a getcwd() before the exec() and it returned /home/~test/public_html/soap/bin/products/browser. I have tried using dirname() and no help. I hope this is clear enought to understand where I am coming from. Thank you. AM 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 Hey Everyone, I have these 3 scripts to upload an image but I'm having an issue because the images uploaded are going to the same directory as the pages. What do I need to change to make the uploaded images go to a folder path called "pictures". Thanks in advance for the help. Script 1 <form name="form1" method="post" action="adminpicturebrowse.php"> <p align="center">How many pictures for this dog? Max is 9</p> <p align="center"> <input name="uploadNeed" type="text" id="uploadNeed" maxlength="1"> <input type="submit" name="Submit" value="Submit"> </p> </form> Script 2 <form name="form1" enctype="multipart/form-data" method="post" action="adminaddupload.php"> <p align="center"> <? // start of dynamic form $uploadNeed = $_POST['uploadNeed']; for($x=0;$x<$uploadNeed;$x++){ ?> <input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>"> </p> <div align="center"> <? // end of for loop } ?> </div> <p align="center"><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>"> <input type="submit" name="Submit" value="Submit"> </p> </form> Script 3 <? $uploadNeed = $_POST['uploadNeed']; // start for loop for($x=0;$x<$uploadNeed;$x++){ $file_name = $_FILES['uploadFile'. $x]['name']; // strip file_name of slashes $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name); // check if successfully copied if($copy){ echo "$file_name<br>"; }else{ echo "$file_name<br>"; } } // end of loop ?> Hey guys! I just joined this forum today, and I'm wondering about something... I see a lot of sites, and in the code of the site, style sheets and javascript includes are references in a manner similar to this... "href='http://www.somesite.com/css/css.php/someDirectory/style.css'" How is this done? The path following the "css.php" is what confuses me. Thanks for any information you have! Hi,
I am trying to setup cakephp cake console in win7 and run cake bake as in the link below.I set up the env variable in win7 as below with a php and cakeapp entry in this Path.I have easyPHP 12.1 and php works fine. I get an error with php in failing to load. dynamic library but the php dir is in the path below so I have no idea .
I cant set my php env var is my problem . The php.ini is in this dir specified below.
http://www.nurelm.co...ols-in-windows/
E:\Program Files\EasyPHP-12.1\php\php546x121019214357\;E:\AA-website design\acl\app\Console\;
|