Include in included file doesn't work PHP [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get useful error messages in PHP?
I have the following html list:
<ul id="ulGroups">
<?php
include('organizer_picturearchive_groups.php');
?>
</ul>
I am trying to include this file, which also includes another file:
<?php
include('lib/organizer_functions/picture_archive.php');
echo select_all_picture_category_groups();
?>
Basically, what I am trying to do is to call a function that is in the picture_archive.php file. I do that in the organizer_picturearchive_groups.php file.
I am including this file in the first file where the html list is. I am not pasting the whole code from there, because it is a lot, but it works.
However the include thing doesn't, because when I tried to make a test echo statement in the "organizer_picturearchive_groups.php" file it works and I can see the text I am printing.
Do you have ideas what may cause this problem ?

Double check the path. If organizer_picturearchive_groups.php is in the same directory as the code, then try configuring the path as relative:
<?php
include('./organizer_picturearchive_groups.php');
?>

Related

PHP's include() function not working xampp [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 1 year ago.
Please bear with with me as I am new to web dev. I am attempting to use the include function in php to display a header on a web page.
I am using two very simple files, placed in the same directory and am using XAMPP.
index.php
<html>
<body>
<h1>Hello</h1>
<?php
include('header.php');
?>
</body>
</html>
header.php
<p>Hello</p>
When I open index.php, the statements from header.php never show up. All I see is one "Hello", as printed in index.php.
I have attempted to follow many tutorials online similar to this (ex https://www.w3schools.com/php/php_includes.asp, https://www.tutorialrepublic.com/php-tutorial/php-include-files.php), but none of them work for me.
Please let me know if you have any advice.
For security reasons you should use the following statements instead of include, unless you have a good reason to not do so:
Either
require_once 'header.php';
or
require 'header.php';
This will cause an E_ERROR in case the file was not found or you don't have permissions to include it. Otherwise you run into the risk not executing code which is mandatory for your program.

Get file name index.php in an inluded file [duplicate]

This question already has answers here:
Get filename of file which ran PHP include
(7 answers)
Closed 5 years ago.
I want to get file name from URL in an included page for example in meta.php
I use basename(__FILE__) but I get 'meta.php'
how I can echo index.php in an included page??
<meta name="description" content="<?php
if(isset($FILEDATA_LANG['page_'.basename(__FILE__).'_keywords'])){ echo
$FILEDATA_LANG['page_'.basename(__FILE__).'_keywords']; }?>">
This has been asked earlier and you could've found your answer within seconds of searching, however, here's a proper response:
Set a variable in your index.php or a definition, such as:
define("THIS_PAGE", __FILE__); or $thisPage = __FILE__;
Then in your file you're including (after this variable), simply use:
<?php echo $thisPage; ?> or <?php echo THIS_PAGE; ?>.
(Keep in mind to check if the variable is set (isset($thisPage)) or (defined("THIS_PAGE")).
Reference: Get filename of file which ran PHP include
I'm trying by adding
.basename($_SERVER['SCRIPT_FILENAME']).
I Hope it would work when i publish this page

PHP placement within HTML page? [duplicate]

This question already has answers here:
PHP in HTML page, Super Quick Advice
(3 answers)
Closed 9 years ago.
I have asked a question leading up to this earlier. Thanks again for your help.
I have updated my .htaccess file in my root directory with the following:
AddType application/x-httpd-php .html
Where within my .html page should I place the php tag?,
I still cannot seem to get my .html page to load the .php script.
If you have followed this guide correctly, then according to the article, you should be able to execute php by simply opening a php tag.
From the article:
Things to watch out for:
If you have an existing .htaccess file, add this to it, do not overwrite it or other >settings may stop working! Always be very careful with your .htaccess file and ask your >host if you need help
Anything in your .html files that starts with your file for some other reason (an XML tag for example) you will need to echo these lines >to prevent errors. For example:
<?php echo '<?xml version="1.0" encoding="IUTF-8"?>'; ?>
Where within my .html page should I place the php tag?
The answer is you can place your php content anywhere in your html page as long as it is inside <?php ?> tag.
even if you have done correct modification to .htaccess file and still your php content is not getting parsed than check whether you are connected to server or not.

php how can i include internal pages by url? [duplicate]

This question already has answers here:
Include another HTML file in a HTML file
(41 answers)
Closed 8 years ago.
for example my website is "myweb.com". how can i do opration like following.
include(http://myweb.com/file);
this is an internal URL.
for example i want to include
http://myweb.com/process.php?action=update
this is not a file
"?action=update"
thus how can i do this operation?
To include pages with PHP, simply put the following code in a.html, where you would like the code to appear:
<?php
include "b.html";
?>
You can't include an HTML document into another HTML document.
You can do that using PHP but the file that includes the other must be a PHP document. In your example a includes b therefore a is a.php while b can stay b.html.
Then inside a.php you can write:
<?php echo file_get_contents('b.html'); ?>
and the content of b.html will be included into a.php.

Multiple content across pages (html) [duplicate]

This question already has answers here:
How to create a template in HTML?
(3 answers)
Closed 9 years ago.
I looked around, but couldn't find a satisfying answer.
Problem:
I have a menu bar that appears on the top of the page. I want it to show across all of the pages on the website. So how would someone do that without copying the same code each time. Would someone use html, php, css, or javascript/jQuery to accomplish this?
Note: I want to have a separate html file to access the information from.
From what I have seen, this is typically done with php using a template file.
The template file may have HTML code in it that you want to display on every page, as well as placeholders for content that is page specific. e.g: template.php
<html>
<head>
<title><?php print $title; ?></title>
</head>
<body>
<nav>Test</nav>
<?php print $content; ?>
</body>
</html>
In this case, as long as $title and $content variables are set, you can then do a include 'template.php'; to output this HTML code in other php files.
Read more about php's include.
It seems that you will need to use include, although an explaination on how to use it (or at least an example can be found here: https://www.youtube.com/watch?v=XmoF-6vshSI

Categories