I downloaded a Template + CSS File for a Website that I'm Building, the template worked well until I tried to break it down and put every code in its own file (for easy modification and editing in the future).
So, when I cut the head part which included (Title + Meta Data .. etc ), and put it in its own file, and replaced it (for sure) with an include() function, I lost the CSS styles and returned to the basic & standard style (Black & white with no extra format .. etc)
Where did I Go wrong? Knowing that here is the include function that I've used:
<?php
include 'files/head.php';
?>
With an URL like file:///C:/xampp/htdocs/test6/index.php PHP is NOT executed. You must run it with apache being involved. Currently you are opening your PHP script as a regular txt or html file - it is just passed to browser without processing.
In order to make include function work you must run it with apache. As you are using xamp, I think you should simply open it with URL like http://localhost/test6/index.php In this case, apache will get that request and pass it to PHP. PHP engine will interpret your PHP script and "replace" include files/head.php with a content of head.php.
If everything is Ok, after pressing Ctrl+U (or looking at HTML with Developer Tools or Firebug) you should see a content of head.php instead of <?php include ....
Please note that css files should be linked with relative URL like css/screen.css. Or absolute URL like http://localhost/test6/css/screen.css. like Search for relative and absolute URLs in google for more info.
Related
Using Google App Engine, I'm trying to display a PHP page that contains html, within which I have more html content from another source. I'm using a PHP tag to include the content, like so:
< ?php include "https://myfileURL.html"; ?>
But it does not show up in the page source code. The html file is in a "/HTML/" folder which is handled as a static_dir in app.yaml. I can access the URL from the browser and the content is there, but if I put that URL in the include tag I get nothing. I can even put bad URLs and I get no errors, no console output... just nothing. The page displays with white space in the middle of the source code.
Any idea what's going on here? Everything works perfectly in localhost.
Argh... backend process... need to catch errors in php, nevermind.
I need to add a meta tag to all files of a website, so I thought about adding that meta tag by PHP code, within header.php, menu.php or footer.php; something like:
<?php addToHeadTag("Meta: favicon='./img/favicon.ico'"); ?>
It has a lot of files and manually changing each file is out of hand.
P.S.: All possible files in which I could include that code are outside head.
First of all, you can place an include file wherever you like in your code. Though that really has nothing to do with the problem at hand.
You should not be using header() for this. header() provides the client browser with meta information on the http response as a whole.
Take a look at this link for usage information on favicons:
http://en.wikipedia.org/wiki/Favicon
In most cases you can just place the favicon.ico in your web root and the browser will pick it up automatically without any markup at all. You can also use a <link> element.
I'm learning php, been trying to make a cms, but when I use an include for the header this results in the page appearing as if it were written in pre tags. There's no errors when I debug or anything. And I'm completely stumped. When I put the header back in without the include it renders just fine.
<?php include("..\includes\layouts\header.php"); ?>
That's the include I'm using.
I've tried using the full path name, tried it in different browsers and using :
include($_SERVER["DOCUMENT_ROOT"]
Check that you are closing your php tags, ending your strings with semi colons etc.. My guess is that your html is being sucked into the php code which freaks out and just dumps it.
Maybe try one of the validators such as http://phpcodechecker.com (I have not used this one so I cannot comment on it's effectiveness)
Edit: I am rereading your post and I think I understand what you are trying to say - your header contains the path to your css and when you put it in a separate php file the css doesn't work? So the first thing to do is determine if the issue with the php path or the css path inside the header.php file. Look at your source code to see if the header code is being included - if it is then play around with the css path - though including the header in a php file will not cause that css path to change.
I am guessing that your header is not included at all from your mention of paths. include() works from the loading file's location. The path it wants is a server path and not a url. The one that you have above: ../includes... means that you have an include folder at the same level as the loading file such as (assume index.php is the main file):
/includes/layouts/header.php
/somedirectory/index.php
The ../ means - drop down one directory then go up from there.
If your path is more like:
/includes/layouts/header.php
/index.php
Then the include would be:
include('./includes/layouts/header.php');
Let me know if that works - if it doesn't try to explain your directory structure.
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"
I am trying to make a template for my website.
Basically taking out all the common stuff out using php's include function.
I have made a navigationbar.php and samplepage.php.
navigationbar has all the links to stylesheets etc.
When they are in the same folder and I include navigationbar.php in samplepage it works just fine.
However when i move samplepage.php to a subdirectory (leaving navigationbar.php in the same folder) and
link navigationbar.php with the menu doesn't come formatted.
it seems samplepage is getting contents from navigationbar.php but navigationbar is not linking to the css files.
Can anyone tell what I'm doing wrong here?
i'm using xampp and have tried with both relative and absolute paths- (include '../navigation.php' and 'localhost/folder/navigation.php')
Make the paths of your css files absolute (i.e. start with / and specify the full path). This will allow them to work correctly from any path.
When including a file in PHP, the url's are relative to the file you are including into. Not to the file you are including.
So you need to change your paths 'navigationbar.php'
Try using something along the lines of this to link to your header/footer files:
include($_SERVER['DOCUMENT_ROOT'].'/path_to/header.php');
and then appropriately link to your .js/.css files within header.
Where your PHP files are has no direct influence. You have to make sure that the resulting HTML has the correct paths to all CSS/JS/img files etc. You may want to post your file structure here and show the code that calls the relevant CSS files.