PHP include code shows one thing but browsers show another - php

I have a series of php includes on a web page that look like this...
<?php include 'folder1/file.php'; ?>
<?php include 'folder2/file.php'; ?>
<?php include 'folder3/file.php'; ?>
They look like the above in my code editor but when I upload to my server it views like this when I look at the source code...
<?php include 'folder1/file.php'; ?>
<?php include 'folder3/file.php'; ?>
<?php include 'folder3/file.php'; ?>
So I thought maybe the file wasn't uploading....so I changed the code to this and uploaded the page....
<?php include 'folder1/file.php'; ?>
<?php include 'folder3/file.php'; ?>
And when viewing that in any browser it viewed as expected, showing just the two includes. Telling me that the web page is uploading properly to the server. I've emptied my cache, refreshed the page and nothing. So then when I change the code back to this and upload....
<?php include 'folder1/file.php'; ?>
<?php include 'folder2/file.php'; ?>
<?php include 'folder3/file.php'; ?>
It stills shows this in the live page
<?php include 'folder1/file.php'; ?>
<?php include 'folder3/file.php'; ?>
<?php include 'folder3/file.php'; ?>
I have PHP installed on the server and all other PHP codes/includes work correctly. The following PHP code does run correctly.
<?php phpinfo(); ?>
Here is the code for folder2/file.php
<div class="propertylistingbox" id="propertylistingbox">
<div class="proplistingleft" id="proplistingleft"><img src="/second-base/images/FirstBase01.png" alt="Second Base Exterior" width="284" height="193" border="0" />
<div class="reservation-request-button">
</div>
</div>
<div class="propertylistingmain" id="propertylistingmain">
<div class="propheader" id="propheader">
<h3>SECOND BASE</h3>
</div>
<div class="propbulletlist" id="propbulletlist">
<ul>
<li>Located In Oneonta, NY</li>
<li>Accommodates 4</li>
<li>High Speed Internet</li>
<li>2 Bedrooms</li>
<li>Close to 3 bedroom apartment "First Base"</li>
<li>1.25 Miles to Cooperstown Baseball World</li>
<li>2.75 Miles to Cooperstown All Star Village</li>
<li>19 Miles to Cooperstown Dreams Park</li>
</ul>
</div>
<div class="propdetails" id="propdetails">
<div class="details-button">
Click For More Details
</div>
</div>
<div class="propspecialsbanner" id="propdetails2"></div>
<div class="propcalendarmaplink" id="propcalendarlink"><strong>CALENDAR OF AVAILABILITY</strong><br />
<strong>GOOGLE MAP</strong></div>
</div>
</div>

Related

Web page is not available in Localhost

I am making a cms application and it was working fine until i made a new page called "session.php" and added a function into that page I then wrote the require once command into the main page of my application and when I run it says "Webpage is not available"...i remove the require once command and my application works again. Does anyone know how to fix this problem?
This is the code for session.php
<?php session_start(); function message() {
if (isset($_SESSION["message"])) {
$output = "<div class=\"message\">";
$output .= htmlentities($_SESSION["message"]);
$output .= "</div>";
return $output;
}}?>
This is the code for the page im trying to load
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php include("../includes/layouts/header.php"); ?>
<?php find_selected_page(); ?>
<div id="main">
<div id="navigation">
<?php echo navigation($current_subject, $current_page); ?>
<br />
+ Add a subject
</div>
<div id="page">
<?php echo message(); ?>
<?php if ($current_subject) { ?>
<h2>Manage Subject</h2>
Menu name: <?php echo $current_subject["menu_name"]; ?>
<?php } elseif ($current_page) { ?>
<h2>Manage Page</h2>
Menu name:<?php echo $current_page["menu_name"]; ?>
<?php } else { ?>
Please select a subject or a page.
<?php }?>
</div>
</div>
<?php include("../includes/layouts/footer.php"); ?>
The code posted looks oddly-formatted, but I'll venture to say it's not a syntax error.
As others stated, you need to learn the "debugging" process which includes monitoring the error.log file (assuming Apache) and the browser's console (where applicable).
During development, it's a good idea to turn on error reporting to make this a bit easier. Place the following lines at the top of your PHP scripts:
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
That won't display 100% of the issues (99.8% give or take), so read up on how to view your server's error log. The answer to your question is hidden in there, I guarantee it.

PHP Include slideshow—not lining up, simple css answer I'm sure

I have simple slideshow on my home page as a php include. It shows up, but it seems to be floating up to the top of the page, and not falling in line with all of the other includes, ie, header, menu, etc. In addition, the image isn't lined up with the arrows. Here is where it lives:
http://www.starhilldesignstudio.com/adventure-suites/index-test.php
And here is the slideshow solo (arrows line up):
http://www.starhilldesignstudio.com/adventure-suites/slideshow-home.php
My html code:
<div id="container">
<div id="header">
<?php include 'menu.php'; ?>
</div>
<div id="mainContent" style="position:relative; z-index:1;">
<div class="center margin-top "><?php include 'slideshow-home.php'; ?></div>
<?php include 'home-blurb.php'; ?>
<?php include 'home-list.php'; ?>
<?php include 'bottom-stripe.php'; ?>
<div id="footer2">
<?php include 'footer.php'; ?>
</div>
</div>
</div>
THANKS!!!
Looks like a misplaced include, place your include function where you wanted to put your file to.
Example you wanted to put it before your content in between your header and footer:
include "header.php"
include "slider.php"
include "content.php"
include "footer.php"
Let us know if this is not the case.
<div id="container">
<div id="header">
<?php include 'menu.php'; ?>
</div>
<div id="mainContent" style="position:relative; z-index:1;">
<!-- Add this... -->
<div style="clear:both;padding-bottom:10px"></div>
<!--<div class="clear"></div>consider making the above style into a class.-->
<div class="center margin-top "><?php include 'slideshow-home.php'; ?></div>
<?php include 'home-blurb.php'; ?>
<?php include 'home-list.php'; ?>
<?php include 'bottom-stripe.php'; ?>
<div id="footer2">
<?php include 'footer.php'; ?>
</div>
</div>
</div>

php included navigation menu not working

I have a php page that has many includes. The whole page runs fine, but for my navigation bar, it does not open any page when I click on it. Please, what is missing here. Any help will be appreciated. many thanks
Here are my codes for the includes
<div id='cssmenu'>
<ul>
<li class='active'><span>Home</span></li>
<li><span>About Us</span></li>
<li><span>Packages</span></li>
<li><span>Partners</span></li>
<li><span>Gallery</span></li>
<li class='last'><span>Contact Us</span></li>
</ul>
</div>
And here is my main page code:
<body>
<div id="wrapper">
<div>
<img src="images/banner.png" width="940" height="200" />
</div>
<?php include('includes/nav.php'); ?>
<?php include('includes/slider.php'); ?>
<?php include('includes/nav.php'); ?>
<?php include('includes/contents.php'); ?>
<?php include('includes/sidebar.php'); ?>
<?php include('includes/footer.php'); ?>
</div> <!-- End #wrapper -->
</body>
Not sure of your file structure, but try removing the '../' on all you links
Change this:
<li class='active'><span>Home</span></li>
to this:
<li class='active'><span>Home</span></li>
Take the ../ out of your path.
When you include the nav.htm to your main page it acts as if it is in the main folder
Therefore if you use '../' it won't find it.

Php different images in every page

I am designing my own site. First I created a template with header.php and footer.php I put them in the includes folder. So, everytime I am going to make a new page like "about page" all I have to do is to call them using the code below:
<body>
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
</html>
Here is the code in my header.php
<div id="headwrapper">
<header>
<div id="logo"><img src="images/adlogo.png"/></div>
<div id="homefeature">622x82</div>
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>portfolio</li>
<li>Blogs</li>
<li>Contact</li>
</ul>
</div>
</header>
</div><!--end of headwrapper-->
But my index.php and my about page have the same header image. Is there a way or code that can accomplish the work for different header images for every page? Example on index.php I want to have image1 and to my about page I want to have image2. That's all thank you by the way I am not using a wordpress my site is not a wordpress.
Another solution.
In header.php you call function $_SERVER['PHP_SELF'] for get page name and then selected image for that page. You could modify like this
<?php
$imageName = "";
if($_SERVER['PHP_SELF'] == "index.php")
{
$imageName = "images/1.png";
}
elseif($_SERVER['PHP_SELF'] == "aboutus.php")
{
$imageName = "images/2.png";
}
?>
<div id="headwrapper">
<header>
<div id="logo"><img src="'".<?=$imageName?>."'"/></div>
<div id="homefeature">622x82</div>
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>portfolio</li>
<li>Blogs</li>
<li>Contact</li>
</ul>
</div>
</header>
</div><!--end of headwrapper-->
Given your structure, I think you can set your header file like this:
<body>
<?php $header_image = "about_us_header.jpg"; ?>
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
and reference the variable in your header:
<div id="headwrapper">
<header style="background: url(<?php echo $header_image; ?>);">
But wait I thought of a better way
you can do it in css like this:
<body class="aboutus">
<?php include("includes/header.php"); ?>
<?php include("includes/footer.php"); ?>
</body>
and in your css stylesheet:
body.aboutus header {
background: url(whatever.jpg);
}

how to add standard elements in php in one line

I have created a few php files Following are their names:
standard_head.php (which contains basic standard html code)
header.php
navbar.php
sidebar.php
footer.php
standard_footer.php (which contains closing html tags)
Page content will vary in every page and would also include html content.
I am trying to create a lot of php pages which will use all of the above pages directly.
Now I can use them directly using include statement for each of them, but I was wondering if it was possible to include all of them together with one just statement ?
<?php include('../includes/standard_head.php'); ?>
<?php include('includes/header.php'); ?>
<div id="wrapper">
<?php include('includes/nav.php'); ?>
<div id="content">
<!-- my page content -->
</div> <!-- end #content -->
<?php include('includes/sidebar.php'); ?>
</div> <!-- End #wrapper -->
<?php include('includes/footer.php'); ?>
<?php include('../includes/standard_footer.php'); ?>
You could so this (note that this is a very basic example and that I wouldn't use this myself without taking into account meta tags, page titles etc.)
template.php
<?php include('../includes/standard_head.php'); ?>
<?php include('includes/header.php'); ?>
<div id="wrapper">
<?php include('includes/nav.php'); ?>
<div id="content">
<?php echo $content; ?>
<!-- my page content -->
</div> <!-- end #content -->
<?php include('includes/sidebar.php'); ?>
</div> <!-- End #wrapper -->
<?php include('includes/footer.php'); ?>
<?php include('../includes/standard_footer.php'); ?>
Then, on a page (say index.php, for example):
index.php
<?php
$content = '<h1>Welcome</h1>';
include 'template.php';
?>
P.S: If you go down this route, make sure that you check out the Output Control Functions first.
Just create a PHP file that has a list of them i.e.
<?php include("this file");
include("the other file");
?>
And then just add that file.
Not really an answer to your question, but you could use a template engine like Twig.
http://twig.sensiolabs.org/
Try using more complex template system like Smarty or some MVC framework like Zend (this is not required but would allow you to create complex sources more easily) and then build script like this:
<?php include('../includes/standard_head.php'); ?>
<?php include('includes/header.php'); ?>
<div id="wrapper">
<?php include('includes/nav.php'); ?>
<div id="content">
<?php echo $menu->getCustomEntries(); ?>
</div>
Where $menu will be your custom object containing methods for displaying menus and submenus...
There is no straight way to include multiple files, as include / require functions except only one argument. though you can use following logic.
`#include_all_files.php
include('../includes/standard_head.php');
include('includes/header.php');
...
use above file in other files
include('includes/include_all_files.php');
`

Categories