Have multiple includes in a php file [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to call 2 functions that i have in 2 separate .php files. Let's say that function1() is in my_functions1.php and function2() is in my_functions2.php.
lets say i have in the same folder a third file called main.php and i want to include the functions from both my_functions1.php and my_functions2.php.
Something like this
<?php
include 'my_functions1.php';
include 'my_functions2.php';
function1();
function2();
?>
For some reason i can't have 2 include files. I am kind of new in PHP and it seems that there is nothing on google about this except of putting all the functions in one file.

Try using include_once. You might be accidentally including the same file multiple times.

Related

How to include a HTML file in a PHP file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to call an HTML file in a php file but cant really get any right answer.
I have tried:
<?php require/include('filename');>
as well as
readfile('filename');
Doesn't work. How do I do that?
If you are trying to get the html content inside a php file, you can change your .html file extension to .php and use include() or require().
Example, if you have a file named headings.html, rename it to headings.php and then use:
require('headings.php');
While require() will produce a fatal error if the file is not found, include() will only produce a warning.

Is it possible in PHP to exit an included file through something like die()? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
My main PHP file includes several PHP files. At the beginning of one of them I'm testing a variable. If it passes the test then I want the whole script to run, otherwise I want to exit. Is it possible or do I have to condition my entire script (and not use anything similar to die())?
Well, normally it is bad practice to just die() anywhere in a script. However if you have a background script for example and you just want to quit, you can use die() everywhere. A better approach is for example to throw an exception and catch it on a top level

When is require ever preferred over require_once in PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
The way I see it, if a file has been included once then any object, function or member in it is defined.
require_once checks if the file is included and if so, doesn't include it again. But when would the event ever arise that someone would go 'this file has already been included so I can use the class inside it, but I'd better include it again because this script needs it'?
Am I missing something?
I use include_once / require_once for classes files, and include / require for html code (let's say a form for example). You shouldn't redeclare the class, but you could insert html code multiple times in your code.
In ye olde days before proper classes, I would sometimes use require inside a for or while loop when doing large imports. Along the same lines, template engines use it for repeated includes of the same file that should fail if the file is missing.

Adding HTML menus to Includes(PHP) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am making a website using HTML. I am not familiar with PHP. I need the navigation and header part to be in a single place. i.e., Once I change the menus in one place it should reflect in all other pages. Kindly help me on this.
Thanks in Advance.
You could use include or require to add your Menu-Html file in every page you wish.
you could add something like this:
<?php
include('menu.html');
?>
wherever your menu should appear in your HTML, having a menu.html file of course.
and you'll need an apache server or any other that can 'read' your php files.
include php documentations
require php documentations

simple php include single htm file safety [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I use this in htm file to include another htm file
<?php include("media/android.htm"); ?>
Is this safe?
Both of them are simple htm file with text and pictures.
Yes, it's completely safe. That's how PHP works.
But, keep in mind that's a php file, not html.
use jquery to load a file
$("#div1").load("media/android.htm");
Try this
include file without php

Categories