Here is my setup: I am coding on a Mac with VMware Fusion loaded (running Windows 8 on the VM). The VM has IIS running on it so that I can do local testing of my code (written in Edge Code/Brackets). I test the code by pointing my Mac browser at [ip address]:[port]/[file]. This works fine usually, but I am running into a problem with my includes.
Here is the structure:
[index.php]
<body>
<?php require '/Library/Includes/header.inc.php'; ?>
hello
[header.inc.php]
<div class="container_16">
<div class="grid_6">
<img src="http://placehold.it/298x48" alt="Logo" />
</div>
<div class="grid_10">
<?php include 'eyebrow.inc.php'; ?>
</div>
[eyebrow.inc.php]
<ul id="eyebrow-links" class="h-list">
<li><img src="http://placehold.it/24x24" alt="User Avatar" /></li>
<li>My Profile</li>
<li>English</li>
<li>Logout</li>
</ul>
This is the output when I view the source from my Mac
<body>
<div class="container_16">
<div class="grid_6">
<img src="http://placehold.it/298x48" alt="Logo" />
</div>
<div class="grid_10">
<ul id </div>
</div>
hello
It's chopping out a bit of my include. When I test this same code on my Windows Machine, it behaves normally and returns the entire include. Has anyone else run into this problem? Any idea what is happening? I appreciate your help!
Jason
The issue seems to be stemming from my first li element. It might be the reference to placehold.it that is breaking the include. Not sure why it only seems to have problems on my Mac and not my PC, but at least I'm narrowing down the issue.
UPDATE
Nevermind. It just continues to break if I have 4 li elements. Abandoning the issue and just ignoring it. Sorry!
Related
Everything works how I want on my live website, but because I'm using absolute URL's in my header.php and footer.php they don't work when I'm working locally (XAMPP) - I can't figure out how to get it working on both.
Header.php
<div id="top"><center><img src="http://cosworth-europe.com/images/header.png" style="max-width:100%;"></center></div>
<header id="header" class="site-header" role="banner">
<div id="header-inner" class="container sixteen columns over">
<hgroup class="one-third column alpha">
</hgroup>
<nav id="main-nav" class="two thirds column omega">
<ul>
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Dealers
</li>
<li>
Products
</li>
<li>
Buy Online
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Code to grab header.php
<?php include($_SERVER['DOCUMENT_ROOT']."/header.php"); ?>
FTP Folder Structure
You should use relative urls, its recomended for portability.
</hgroup>
<nav id="main-nav" class="two thirds column omega">
<ul>
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Dealers
</li>
<li>
Products
</li>
<li>
Buy Online
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Always use relative URLs, at least to the domain.
<link rel="stylesheet" href="/css/style.css" />
If you really wanna use absolute URLs, set a variable as $homeroot and use it this way:
<link rel="stylesheet" href="<?php echo $homeroot; ?>/css/style.css" />
And you can declare it this way:
$homeroot = "http://my.example.com";
If you still want that to be more better, you can use this way:
$homeroot = $_SERVER["HTTP_HOST"];
You can do two things.
First -
Home // The relative urls
Second -
Define a variable with the host name -
$host = ($_SERVER['HTTP_HOST'] === 'www.cosworth-europe.co.uk') ? 'http://www.cosworth-europe.co.uk' : 'http://localhost';
And
Home
You should not use absolute URLs, if you sometimes have to change something you will have a big mess with it.
You should use either a function or relative URLs.
Function example:
function getURL() {
//get THIS ($develop) value from a config file
$develop = true;
return ( $develop ) ? "localhost" : "http://".$_SERVER["HTTP_HOST"];
}
i.e.
Home
QUICKHELP:
Just edit your hosts file like this:
127.0.0.1 www.cosworth-europe.co.uk
Relative URLs (relative from doc root in this example)
<ul>
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
</ul>
If you want to make it work without editing your source file:
Actually, you shouldn't have done with absolute URL's, but still you can make it to work locally, you need small changes in hosts file. I don't know which OS you are currently in, so you can edit hosts like this:
Ubuntu:
In your terminal, type
sudo gedit /etc/hosts
You will be required to enter your password.
In the file opened add this line to the end:
127.0.0.1 www.cosworth-europe.co.uk
Windows:
c:\windows\system32\drivers\etc\hosts
Open this in notepad with administrative privilege and add the above lines. Now local works in the similar way to your live website.
[But make sure to remove these lines, if you want to access live website (www.cosworth-europe.co.uk)]
See this for pictorial representation. In this method you need not change your files for now. But it is strongly recommended to use relative URLs for excellent portability!
Let me re-explain my problem.
My header is stored in header.php, I'm using <?php include('/header.php');?> to grab it. This works fine on all web pages in my root.
But, I have a folder called Catalogue in my root with more web pages, so then I change it to <?php include('../header.php'); ?> which again works fine.
however, I am sourcing a few images in my header.php. The images do not appear on web pages in my catalogue folder, because I am sourcing them from the images folder in my root <img src="images/cosworth2.jpg">
I can't use <img src="../images/cosworth2.jpg" because this will then affect the images that work fine on the web pages that aren't in my catalogue folder.
Does this make sense?
I need to tell my header.php to source all of my images from the root even if my web pages are in other directories.
Header.php
<div id="top"><center><img src="images/header.png" style="max-width:100%;"></center></div>
<header id="header" class="site-header" role="banner">
<div id="header-inner" class="container sixteen columns over">
<hgroup class="one-third column alpha">
</hgroup>
<nav id="main-nav" class="two thirds column omega">
<ul>
<li>
Home
</li>
<li>
About Us
</li>
<li>
News
</li>
<li>
Dealers
</li>
<li>
Products
</li>
<li>
Buy Online
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
<div class="container"><img src="images/cosworth2.jpg" style="max-width:100%; height:auto; float:left; margin-right:20px; margin-top:20px;">
<p style="padding-top:25px;">Welcome to <strong>Cosworth Europe</strong>. This website is specifically for Cosworth Aftermarket & Performance Products. For any other enquires please visit Cosworth.com. For more information, feel free to visit the About Us page.</p></div>
</header>
Use an absolute path.
<img src="/images/..." alt="...">
Describe the location of your images (and stylesheets, etc) relative to the root of the website.
To add to others answers, you could define() a PHP Constant for the purpose of setting the absolute path. This would help if you ever had to change the directory/path.
//perhaps add this in a config file or at the top of the header.php file
define( 'IMAGE_PATH', '/images' );
//use in any other file
<img src="<?php echo IMAGE_PATH; ?>/image1.png" />
I'm in the process of creating a website (a beginner obviously) and for some reason, on one of my pages, the footer section is MUCH longer than it is supposed to be. Its werid because on other pages, it looks fine. I used the exact same code on a new page and the footer is all out of whack. Here's what I get when I inspect the element on Chrome:
<div id="skel-layers-inactiveWrapper" style="height: 100%;">
I can't find anything regarding inactive Wrappers or anything of the sorts in any of my css files either. Thanks for the help.
Make sure you have you a doctype defined
<!DOCTYPE HTML>
Solved the issue for me.
*I know I'm a bit late on this
try to hide the element <div id="skel-layers-inactiveWrapper">
The CSS
#skel-layers-inactiveWrapper{
display:none!important;
}
Try changing the "100%" to a smaller value, or post more code so we have more to work with :)
Height of 100% refers to the height of the container. The chances are that the instances that work have a surrounding DIV which this one does not and so it is probably taking the height of the entire body (or much larger div) and doubling it.
Here is the entire code in context. The only tags it is embedded within are and tags.
<footer id="footer">
<!-- Contact -->
<h2 class="major"><span> Get in touch</span></h2>
<center><ul class="contact">
<li><a class="icon fa-facebook" href="#"><span class="label">Facebook</span></a></li>
<li><a class="icon fa-twitter" href="#"><span class="label">Twitter</span></a></li>
<li><a class="icon fa-google-plus" href="#"><span class="label">Google+</span></a></li>
</ul></center>
<!-- Copyright -->
<div id="copyright">
<ul class="menu">
<li>© Govpal. All rights reserved 2014</li>
</ul>
</div>
</footer>
I'm working on a login system for a website in which the top right corner will change depending on whether or not the user is "signed in" (a check against a session variable). I am using the following to try and show only one these two states.
<?php if(isset($_SESSION['id'])): ?>
<div class="large-2 large-offset-5 columns">
<p class="right text-pad-top">#MuffinTheFox</p>
</div>
<div class="large-1 columns">
<img class="avatar" src="https://pbs.twimg.com/profile_images/429861192207982592/lxaKQ4Rp.jpeg">
</div>
<?php else: ?>
<div class="large-2 large-offset-7 columns">
<a class="right text-pad-top" href="login.php">Log in/Sign up</a>
</div>
<div class="large-1 columns">
<img class="avatar" src="http://placehold.it/50x50">
</div>
<?php endif; ?>
The problem is, when I upload the code to my server and run it, both HTML blocks display, regardless of the PHP statements.
There aren't any obvious errors and according to my research into the topic, this should work. Also, I tried the way without the endif; statement as well by using brackets, and that didn't work either. At this point I'm somewhat lost as to why this is happening and any help or insight would be appreciated.
Edit: Something of note, the PHP is embedded into a HTML document with a .html extension. I was under the impression that you could just inline php into a html document without issue, but I have a feeling that this might be the cause of the issue.
Your file is not getting parsed as PHP because PHP is not configured to parse .html files unless you tell it to. See this question for insight into how to do that. In the meantime, change your file extension to .php and it should start working as you expect.
I building my 1st responsive & dynamic website. I tested it locally on WAMP and all my sections show up but when I moved it to my 1and1.com production server my php includes didn't work. I checked the PHP versions and WAMP and 1and1 are using PHP 5.4.
Can you tell me what I overlooked or did wrong?
The PHP code is:
<?php include_once('/includes/Footer.php'); ?>
My footer looks like this:
<div id="footer">
<footer class="row">
<div class="large-12 columns">
<hr>
<div class="row">
<div class="large-8 columns">
<p>Jersey City Dance Academy 107 Westside ave. Jersey City, NJ 07305</p>
</div>
<div class="large-4 columns">
<ul class="inline-list right">
<li>Terms of use</li>
<li>Privacy Policy</li>
<li>Site Map</li>
</ul>
</div>
</div>
</div>
<div class="large-12 columns">
<div class="row">
<div class="large-8 columns">
<p>(201) 435-8943 <a mailto="Info#JerseyCityDanceAcademy.com">Info#JerseyCityDanceAcademy.com</a></p>
</div>
</div>
</div>
</footer>
</div> <!-- end #footer -->
*******UPDATE Jan 25th, 2014*****************
I moved all CSS, JS & includes files so the webpage could find them in the relative path but my includes are still not showing up. Picture showing file locations in FTP program.
http://i.stack.imgur.com/R5H94.jpg
additional 1and1 may be Case sensitive while your WAMP isn't. Check case of your filenames, Footer.php is not footer.php
You are using absolute directories for the include command.
<?php include_once('/includes/Footer.php'); ?>
Absolute directory may be different in your new hosting. You should either check the directory in which the Footer is contained or use relative directories.
<?php include_once('includes/Footer.php'); ?>
This will give you a relative path, which your local and live server may read differently.
This assumes that the 'includes' folder is in the same place as index.php
Alternatively (and the recommended method) is to have a path to the root via a variable in front of your includes, like:
<?php include_once($site_root.'includes/Footer.php'); ?>
You could even define that as a constant or put all your important data (like root paths) in an array.