I have a very basic question I just can't seem to figure out or find the answer too. My php won't work on my local host (wamp) or when i upload it to my website/server.
I simply want to "include" two files on my index.php file to display additional html. For whatever reason, the php won't work and won't display anything outside of what is currently in my index.php file.
Here is my index.php
<php? include 'inc/header.php';?>
<div class="container">
<p>main content.what is going on</p>
</div>
<php? include 'inc/footer.php';?>
here is an example of my header.php file..
<!doctype html>
<html>
<head>
<title>stuff</title>
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Is stuff here?</h1>
</header>
I just can't seem to figure it out and any thoughts would be VERY helpful.
You have PHP start tag wrong. It should be
<?php
Related
I want to separate my code to make it clearer. To do so, instead of having one big php file I spare them and keep one "main" file where I include the others when I need. The problem is that CSS only apply to the "main" file, but not to included files.
I'm pretty sure this is not a path issue, for I'm working with every files in the same folder (I know it's not the best way to work, but so far I only have few files so it's not a big deal). I have double checked eventual writing mistakes.
Here is my "main" php file :
<!DOCTYPE html>
<html>
<head>
<title>A very nice title</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<meta charset="utf-8" />
</head>
<body>
<?php include("file2.php"); ?>
</body>
and here is my "file2.php" file :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
<meta charset="utf-8" />
</head>
<div class="beer">
<img src="simple_beer.png" alt="beer picture"/>
<div class="description>
<p> a simple text </p>
<form id="add" action="[nothing interesting]">
<input type="number>
<input type="submit" value="add to card">
</form>
</div>
</div>
So i'm using the same CSS files for both php files. But it's not working on the file2.php when I have a look at it (I'm working on a local host). I've tried to delete cache from my browser (firefox). If you're wondering why I'm working on php files instead of HTML, it's simply because I intend to add php code later.
I have been looking for a solution for almost two hours, nothing seems to work. Thanks in advance !
Include everything header-related inside main.php file, remove head section from file2.php and then include file2.php in the body section of main.php. When you include that file, it will get everything that is above. That means whatever you have in main.php before include() function, will be accessible in called file (thanks to that you can link everything once and have it available in all called files).
Include() brings full code structure from the called file which you do not need (talking about head tag) if main file will hold everything that you need inside tag.
I am trying to use PHP's include function in conjunction with html but it is not working. I'm just messing around with the tag, it seems to be very simple but i cannot figure out why it is not working...
here is the template.php page:
<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<link href="css/layout.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="wrapper">
<?php
include ("include/header.php");
include ("include/leftcolumn.php");
include ("include/rightcolumn.php");
include ("include/footer.php");
?>
</div>
</body>
</html>
and here is the header.php page that I am trying to include:
<header>
<p>Header.</p>
</header>
The only thing i could think of is the wrong directory, I have an include folder which is where the header.php is and referenced that in the include tag...unless I'm wrong, any tips? Thanks
http://php.net/manual/en/function.include.php
you dont need to use parenthesis try :
<?php
include "include/header.php";
include "include/leftcolumn.php";
include "include/rightcolumn.php";
include "include/footer.php";
?>
and make sure the paths correct.
edit:
every exemple on the php manuel are dont have parenthesis.
And a question. where exectly you try to execute your php file. just in a browser or using any wamp server aplication to simulate server side action for your php ?
Remove your Brackets ()
<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<link href="css/layout.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="wrapper">
<?php
// removing brackets... hopefully it will be working....
include "include/header.php";
include "include/leftcolumn.php";
include "include/rightcolumn.php";
include "include/footer.php";
?>
</div>
</body>
</html>
I didn't tested your code, but be sure of your path (is your template.php file to the root, before your include folder?) (it's crazy to say, but pathing are a frequent problem, and it can easily making you mad)
Or, try this syntax too :
include 'include/footer.php';
Recently I've been trying to do php includes for my html page.
I made the php file in Dreamweaver which looks like this
<li>Home</li>
<li>About</li>
<li>Contact</li>
filename: nav.php
Then I tried to include it inside my main html page:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<ul class="nav"><?php include("nav.php");?></ul>
</body>
</html>
filename: index.html
I also want to use css to style my php include, how do I do that?
Any help would be appreciated.
Here is the steps/structure you should follow.
1) Your file which needs to be included which you have given a name "nav.php" which is correct.
2) Your main file should also be php file. For eg. it's name should be something like "MyMain.php"
3) As you want to apply css. You can include external css in your main file (here i.e MyMain.php). Or else you can also write css in the same file (MyMain.php) in <style></style> tag.
To load or "include" CSS you can add this in your header:
<link rel="stylesheet" href="style.css" />
I'm having a problem where my page automaticly puts two doublequotes outside php tags ("")
This happens as soon as the page contains <?php and ?> and I can't find out why.. Nor should it be my php settings because files in other directories work... except for this files somehow, here are the codes:
index.php
<html>
<?php include 'include/head.php' ?>
some data to test
</body>
</html>
head.php
<head>
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
</head>
<body>
<div id="test">test data</div>
and both of the CSS files are empty, I work with .css.php because I have been told that this could greatly improve loading speeds.. This all together gives me the following code in chrome, and Internet explorer:
<html>
<head></head>
<body>
"
"
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
<div id="test">test data</div>
"
somedatatotest"
</body>
</html>
EDIT: Real browser source:
<html>
<head>
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
</head>
<body>
<div id="test">test</div>
some data to test
Change your index.php file to this:
<html>
<head>
<?php include 'include/head.php' ?>
</head>
<body>
<div id="test">test data</div>
</body>
</html>
And your head.php file to this:
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
No questions, just do this. Promise it will solve your problem.
EDIT: Also, why is it common.css.php and not just common.css?
EDIT 2: Okay, do this then. You've got to atleast try some of the suggestions, otherwise no one will want to help you.
//index.php
<html>
<?php include 'include/head.php' ?>
<div id="test">test data</div>
</body>
</html>
//head.php
<head>
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
</head>
<body>
<div id="test">some head test data</div>
You're not passing a well formed HTML document to your browser, and the rendering engine is trying its best to show what it has got.
Since your HTML isn't well formed, you can't expect a predictable output. Fix your source, and the problem will be solved
Okay I found the problem, It seems that my Notepad++ settings were wrong, it would create files with the UTF-8 coding and ANSI enabled, but since I set my settings to UTF-8 (WITHOUT BOM) and ANSI coding ignored everything seems to be workign fine again.
I intent to create a template PHP file, this template will only serve the design, not the content. The purpose is to decrease the development time in a sense that when creating a new PHP file or new module, I can only need to concentrate on the main function of that PHP file not the design. Once I created the new file using the template, it should be able to display the consistent design and serve its specific function.
The issue is that I am not sure on how to make the design of the template works and applied to all of the new files created regardless of the location (as long as it is within the root directory).
As an example:
root directory (www.example.com): /
homepage (www.example.com/index.php): /index.php
css file: /style/style.css
template file: /template.php
newly created file (www.example.com/subone/find/css/file.php): /subone/find/css/file.php
another newly created file (www.example.com/subtwo/locate/css.php): /subtwo/locate/css.php
Content of the homepage (which is created base on the template.php, but the CSS file location is hard coded):
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
<div id="header">logo and login form goes here
<div class="nav"> navigation goes here;</div>
</div>
<div id="main">main content goes here;</div>
<div id="footer">footer goes here; </div>
</body>
</html>
but, when I created a new file, /subone/find/css/file.php
the location of the css must be changed and specified manually, like this:
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="../../../style/style.css" />
</head>
<body>
<div id="header">logo and login form goes here
<div class="nav"> navigation goes here</div>
</div>
<div id="main">main content goes here;</div>
<div id="footer">footer goes here;</div>
</body>
</html>
So, what I want to achieve is that, when creating a new file (/subone/find/css/file.php), I don't need to do anything, I can straight away concentrate on the main section:
<html>
<head>
<title>Testing</title>
...style.css is handled automatically
</head>
<body>
<div id="header">logo and login form goes here
<div class="nav"> navigation goes here</div>
</div>
<div id="main">main content goes here;
<?php
//I can continue to edit the file from this line onward
echo "I am concentrating on the main function of file.php right now!!";
?>
</div>
<div id="footer">footer goes here;</div>
</body>
</html>
example page can be seen at (only the desired design): neoborn.kodingen.com
I accept any answers as long as it can achieve my intention (template).
Thank you :)
Why don't you use absolute paths when referring to CSS files and other resources in your template file?
For example:
<link rel="stylesheet" type="text/css" href="/style/style.css" />
There are 2 options,
Use absolute paths for your css files <link rel=stylesheet href="/style/style.css">
Use HTML's <base> element to cause all relative paths on the page relate to it.
I would use a easy to install template engine. That will help speed up development and still give you the freedom to do whatever PHP you like.
Try http://www.raintpl.com/ that should be quick and easy for you to install and get back to coding the pages. If you include it in your PHP inc folder, it will be available for every PHP file you create. So you won't need to add an include line at the top of each PHP file.
Index.php
<?php define('BASE_URL', 'http://localhost'); ?>
Template.php
<link rel="stylsheet" type="text/css" href="<?php echo BASE_URL; ?>/style/style.css ?>" />