Combining 2 PHP scripts - php

I have 2 web pages. Both have PHP scripts. Playing.php has a table showing the last 20 songs played on my shoutcast server. I'm trying to get that displayed on my index page.
Index.html: http://www.deamon.org
The page I'm trying to add is
http://www.deamon.org/scxml/playing.php
Can I do this with include function and echo or is there a better way.

The quickest and easiest way is to use an iframe:
<iframe src="http://www.deamon.org/scxml/playing.php"></iframe>

My best suggestion would simply be to include it with a simple include statement or using an iframe
<?php include("link to file"); ?>
<iframe src="link to file"></iframe>

You could use a PHP include you can do this by adding this line of code into the index file.
First you would have rename index.html to index.php and then place the following code in-between the tags where you would like the page displayed.
<?php include '/scxml/playing.php'; ?>

My suggestion would be to include the .php file into your index page. However including PHP code into an HTML type page requires reconfiguring your server. Instead, do the following:
Change your index.html file to an index.php file. It will be read and rendered the same way without requiring any changes. (make sure that the index.html file doesn't exist on the server so that the index.php file automatically gets picked up
add the following line of code into your index.php file:
<?php include('path/to/playing.php'); ?>

Related

header.php include only working on home (index.html) file

I am trying to add an include of "header.php" to my inside pages BUT my PHP syntax is showing up as a comment in chrome's editor. The SAME "header.php" works fine on my home/ "index.html" page but will not on any other. Some points to note:
The route of "index.html" and "inside-page-example.html" are the same, so it's not a route problem.
The code is not written as a comment in the file. It reads:
<?php include ('inc/header.php'); ?>
So frustrating! :(
instead of
<!--?php ... ?-->
Try:
<?php ... ?>
and also change your file extension to .php (everywhere you are using php)
You do need to take out the comments, so that it's just <?php and ?>. The green text in Chrome indicates that it is being read as a comment.
You'll also need to save the file as .html with filetype as "Hypertext Markup Language" not just .txt, but I have a feeling you have that covered.
Also, you'll need to make sure that every file is in the same folder. If "inside-page-example.php" is inside a different folder, then you will need to add a forward slash or /../ for every folder you want to go up. So if you have header.php and index.php and a folder called Resume all inside "Home" folder, then when you are on Resume/index.php, you'll need to say include_once("/header.php");. A really great tool that I use when using includes is to replace the slashes with $_SERVER[DOCUMENT_ROOT]. So the include would read like this: include_once("$_SERVER[DOCUMENT_ROOT]/header.php");. This will grab header.php from the folder at the root of the server. Does that make more sense?

How to make page blank when user access php file directly?

So I'm trying to make a theme from my Html file. And using require('file.php') where file.php is a series of different components of my theme. Now when I access the file directly, I still see the html. How do I make it display a blank page when user accesses the file.php directly?
Explanation
So let's say I make index.php and I want to include the header file(header.php)
When I require('header.php'), everything works perfect. Now when I try to access the header.php, I can see the html content of it. How to I make this appear blank instead of seeing the header.php piece?
Thanks
In that case, If you want to execute header.php inside the index.php or etc. You need to add or define a flag in parent files (wherever you want header.php to be executed or simply adding in to the common file which is called in all parent files), In header.php file you need check the defined flag is set or has some value. If it is not set, then stop execution by using die(); function.
In index.php,
<?php $HeaderAllow ='1'; ?>
In header file,
<?php
if($HeaderAllow=='' or !isset($HeaderAllow)){
die();
}
?>
you can use $_SERVER['SCRIPT_FILENAME'] here to check and then make page blank in header.php.
<?php
if($_SERVER['SCRIPT_FILENAME'] == 'header.php') {
exit();
}
Putting the include files in a seperate folder and protectinng with .htaccess is good idea.
Same issue here.
deny direct access to a folder and file by htaccess
The easiest way is to put your includes in a directory and deny access to that directory in your .htaccess file

included files php do not appear in a browser

I have a php page(index.php) that includes another html file(footer.html). Am using dreamweaver, and my problem is: The included file(footer.html) shows in the main file (index.php) in dreamweaver design view, but does not show in the browser preview. I have both the php files in the root directory, so they're at the same level. I have tried using require rather than include with the same result. My include code is:
<?php include("footer.html");?>
does anyone see something wrong off the bat?
Do realy exist file "footer.html"?
If no create them.
Is file "footer.html" in the same directory as "index.php"?
If no add it to the same directory.
Do you have any content in your "footer.html" file?
If no add any and check if it appears on page.

PHP include form trouble

I am having trouble with PHP includes, and I am not entirely sure I am using them correctly. What I have so far is an HTML page that I want to add a search bar to. My PHP code in the HTML page looks like this.
<?php include 'site/tools/search.php'; ?>
The problem I am having is that the search bar is not displaying on the HTML page. I know that the search bar works, because I have browsed to that file location and worked with the actual search bar.
You cannot use PHP code in HTML documents. Change the extension of your .html file to .php and it should work without affecting anything. This would mean any links to the page would have to be changed accordingly.
Check that your file ends with .php (not .html) and everything should work (your include statement is correct). If this fails, try using an absolute URL.
Use the complete path to the file with your include statement. Like so:
<?php include '/home/yourusername/public_html/site/tools/search.php';
It may be a problem with the path of the file. If you are using a relative path try adding "./" in the begginning like this: "./site/tools/search.php"

How do I add HTML code to a .html file from another file?

I'd like to input some code, for example a menu in HTML from another file so that I can edit that menu and then all the menus for all the sites would change as they'd be linked to that page. Is there a way to do so without making all the pages .php?
Server side includes are going to be the best way to do this, but if that's really not an option you could do it with JavaScript - load the contents of another file using AJAX when the first page loads, and insert that content into a specified element on the first page.
For example (using jQuery, because it's simpler to write out here):
$.get('page2.html', function(data) { $('#whereToPutContent').html(data); });
You don't need to make all the pages in php. As long as the page you're going to include doesn't have php code, it can be pure html, or txt, or whatever.
The include HAS to be in a php page, that's all.
So, in your PHP page, just use include (or require) and you're set. For example:
<?php
include ('menu.html');
?>
Yes, it's possible with frames or AJAX (use <script src>). However, frames are deprecated and AJAX is only reliable if the browser has JavaScript enabled.
So PHP is the (only) solution here. Here are the four possibilities:
<?php
include 'menu.html';
require 'menu.html';
include_once 'menu.html';
require_once 'menu.html';
?>
You probably want to use include_once for a menu so that it is only include one time. Or if you are sure that it is only included one time you can just use include. require stops the script if it can't find the file, so that's probably not what you want.
You may use server-side includes (SSI):
include ./includes/include.html
or
include ./includes/include.ssi
or
include ./includes/include.shtml
iframes:
<iframe src="http://website.com/index.html">
<p>Your browser does not support iframes.</p>
</iframe>
or javascript (AJAX):
STEP 1: add code to html file
<script language="JavaScript" SRC="http://yourwebsite.com/js/file.js"></script>
STEP 2: configure [apache] server by adding to .htaccess file. Add this line:
AddType application/x-javascript .js
The pages including the menu page would have to be PHP yes, the menu page itself doesn't have to be. For this you can use: include()
include './file.html';
you can dynamically display menus (or whatever) with JavaScript.

Categories