php multiple include not working on the same page - php

I've searched for an answer but found none. So, here it is: simple php page, before anything else I have:
<?PHP
session_start();
require_once("./include/inside_config.php");?>
On the same page, in the body, I have to include another page, a jquery thicker, like this:
<div style="text-align:center; color:#cccccc;">
<?php include('thicker_it.php');?>
</div>
The last one returns error (Warning: include(thicker_it.php) [function.include]: failed to open stream: No such file or directory in...) The fact is that the file exists, at that location (writing before "./" does not resolve the problem).
Note:
the DNS is forwarded to another server (I use another domain's server, the same provider GoDaddy).
the full-path solution does not work either (I changed the php.ini but the error persists).
Please help. Thanks!

This problem can only be one of the following two:
a) Your file doesn't have read/execute premisions for the worker process owner.
b) The file is not where you think it is.
include(file.ext)
This is known as relative path and this is telling PHP that your file is located in the same directory as the script that is currently running, while:
include(/file.ext)
tells PHP that the file is in the root directory, this is known as absolute path.
The solution deppends on where your file is currently located, the relevant part of your directory structure could help us a bit more to help you.

Related

PHP Form on WordPress (4.6.1) site

forgive me if is a basic question...
I am working on setting up a form on our new hosted Wordpress site - currently hosted inhouse on IIS/PHP/Wordpress server (I am not JR - but this stuff escapes me and would really like to figure it out!! I hate not knowing)
The OP that made the form / got it working is no longer around and I am sure there is a better way but this is what I have - a request form.
When I load the required files in the same path - copy the code from the WP page and paste it in the new Wordpress page - it loads without formating, the pick box doesnt look right and when I submit the form - I get these below PHP file errors. I can open the path in my browser and it exists - I see the class.GA_Parse.php file)
I checked execustion rights on the scripts - its set to execute - apart from that I dont know why it cant fine the files and that include_path I dont see via my hosting companys dir structure via FTP.
Any help would put me forever in your debt, I hope to be able to return the help, this site looks amazing!
Cheers,
Warning: require(/gaparser/class.GA_Parse.php): failed to open stream: No such file or directory in /home/comany/public_html/stage/forms/getfreetrial_v3.php on line 4
Warning: require(/gaparser/class.GA_Parse.php): failed to open stream: No such file or directory in /home/company/public_html/stage/forms/getfreetrial_v3.php on line 4
Fatal error: require(): Failed opening required '/gaparser/class.GA_Parse.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/company/public_html/stage/forms/getfreetrial_v3.php on line 4
PHP will load pages based on the disk location, not the URL. This means it's starting in the server's root / directory, not in /home/company/public_html/stage/forms. When including a file, either you have to use a relative link:
require('./gaparser/class.GA_Parse.php'); // starts in the same directory as the file
Or use PHP's server variable to get the document root:
require($_SERVER['DOCUMENT_ROOT'].'/gaparser/class.GA_Parse.php');
The paths may need to be tweaked depending on where the file actually is.

Run an Html file in Apache Server from outside web root

I have a folder which contain HTML, CSS, JS, image files across various folders. For security reasons I want to place it outside the web root.
I have come across a solution using file_get_contents function of PHP.
But then there is a problem with hyper-linking present in the page. For example, the link to the javascript file in the page:
<script src="lms/APIConstants.js" type="text/javascript"></script>
searches for the file in http://localhost/lms/APIConstants.js and returns an error of
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/lms/APIConstants.js
I am aware of using .htaccess file for hiding some folders from the web root. I am looking for some other insightful solution.
Finally solved this.. Might be helpful for others.
Steps that were followed:
Use a separate file for reading from outside web root (say filereader.php).
Call this file with URL encoding the local file path. http://localhost.ca/lms/filereader.php/path/to/local/file.html
Parse the URL to get the path - /path/to/local/file.html
Apply PHP's readfile() function to read from the obtained path.
Doing this, all the hyperlinks in file.html gets loaded from the following path.
http://localhost.ca/lms/filereader.php/path/to/local/
The mime-type for each file has to be defined. Also a proper http response code is to be thrown using PHP's http_response_code() when a file is not found.
Note: You might need to enable AcceptPathInfo in the Apache configuration.
when you include a file then code/script runs according to new path on which it is being included.
It finds the APIConstants.js file into the folder Ims which is in root directory.
but actually it is outside the root directory.
So give the path like this.. If Ims folder is one step down to the root directory.
src="../lms/APIConstants.js"

PHP website Warning: require(/../core/database/connect.php): failed to open stream

Hi I want to put my website(web application in PHP) on a server of my school and it’s for a project for school. So I had read the instructions of my school where I had to put my source code. I had to put in a folder called ‘Html’ and according to my school that is used for php hosting. After putting my files in that folder I went to browse to my website.
But it doesn’t show me the website when I browse to it. Instead it had given me a error message, see link below:
http://i.imgur.com/dfYxc02.jpg
After reading the error message I thought it had something to do with this line of code in connect.php file:
mysql_connect('145.92.203.240', 'user', mypassword');
I thought that was looking fine, but I also tried “mysql_connect('localhost, 'user', mypassword');”, but I still receive the same error message.
Furthermore I had tried in “/etc/init.d” to restart apache. For this I used the following command:
apache2 –k restart
But I couldn’t restart apache because I don’t have permission.
I also had tried in “/var/www/localhost/htdocs” to show index.html on the browser. But that didn’t work as wel. I also couldn’t remove te index.html file and replace it with my source code.
Could someone please tell me the solution in steps?
Okay here we go:
You're trying to include a file and the location is wrong
For instance, require('config.php'); will assume the file is in the same folder as the script. require('./folder/config.php'); will assume the file is in the folder. So you may want to check exactly where connect.php is.
The error about include_path
It seems as if you have a var include_path defined somewhere, might want to check that out. If you migrated it, you need to change the var to the new location.

Viewing PHP properly with my Localhost using XAMPP

This is my first attempt at using a localhost while editing PHP website files (I'm a HTML girl, but have been asked to make some aesthetic changes to a PHP site).
I've installed XAMPP on my Mac already and configured it (as far as I know). MySQL Database, ProFTPD, and Apache Web Server are running. I've succeeded at viewing a simple index.php file from the htdocs files using localhost/index.php. I've placed the entire website directory (named newsite) inside the htdocs folder. When I attempt to view the website in Firefox or Safari via localhost/newsite/index.php I get this message in the browser:
Warning:
include_once(/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc):
failed to open stream: No such file or directory in
/Applications/XAMPP/xamppfiles/htdocs/newsite/index.php on line 2
This is referring to a block of PHP at the beginning of the index.php document. I've checked, the simplepie.inc file is in file inc under file newsite. If I try go around it by commenting out that section of code and any related calls, the browser goes blank. Can anyone please tell me what else I need to do to just view these files via localhost?
Okay, this is simple but might be complex. So you state:
I've checked, the simplepie.inc file is in file inc under file
newsite.
And then the error states:
Warning:
include_once(/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc):
failed to open stream: No such file or directory in
/Applications/XAMPP/xamppfiles/htdocs/newsite/index.php on line 2
So the error is being thrown because it is trying to read this file:
/Applications/XAMPP/xamppfiles/htdocs/inc/simplepie.inc
But it is located here:
/Applications/XAMPP/xamppfiles/htdocs/newsite/inc/simplepie.inc
What are the actual contents of that include_once?
Since you will probably be moving this site from one place to another, I recommend doing this. I am assuming I know what your include_once looks like, but the general concept holds true.
First, in your index.php or main config/init file (if you have one) add this line:
$BASE_PATH='/Applications/XAMPP/xamppfiles/htdocs/newsite';
Then for your include_once change it to read:
include_once($BASE_PATH . '/inc/simplepie.inc');
Basically that will do the equivalent of changing the include_once to this:
include_once('/Applications/XAMPP/xamppfiles/htdocs/newsite/inc/simplepie.inc');
But the flexibility of using $BASE_PATH is it allows you to change the general site $BASE_PATH in one place & then use it wherever in your site you wish.

include statement using a variable in the filename

(Please be patient, this does have something to do with include.) I am waiting for a domain to transfer over and am trying to set it up on the new hosting service ahead of time. I realized that on the old site all the path names were absolute, so all my links on the new host point to pages on the old host. I decided to make them all relative (for future possible moves also). I first did it like this:
index.php
include ('./header.php');
header.php
include "./panel.php";
panel.php
Contents of panel.
This works, and my page displays:
Contents of panel.
Then I decided to set a variable for the domain because I want to include this header file from files in subdirectories and I can use the domain variable to make an absolute path. Right now I have a temporary domain name, which I can change later to the real domain name when the transfer comes through. So I changed header.php to:
$domain="http://tempdomain.com"; //I can change this after the transfer
$panel=$domain."/panel.php";
echo $panel;
if ((include $panel) !== 1)
{
echo "<br>include failed";
}
What I get is:
http://tempdomain.com/panel.php
include failed
I've looked at various sites for include syntax, but I can't find any error in my code. All these files are in the / directory. Any ideas?
When you include, you have to give the directory structured, not the url.
Your hosting server path may be home/public/www/htdocs/your_directory_name/panel.php something like this. Then it will work.
remort include is also posiible
if
1. server's php.ini should allow it.
2. the file which will be included should not be preprossed before include. That means it must return unprocessed code :)
First, the allow_url_fopen flag must be set in php.ini. Otherwise remote include() cannot be done. Run var_dump(ini_get("allow_url_fopen")); to see if it is the case.
Second, "Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled." - see PHP docs
Third, your remote PHP script must produce valid PHP code as output. If you include() via http, then not the script itself, but its output will be included.

Categories