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.
Related
I am having troubles with including a file that has an included file with some js script library's in it.
index.php
<?php
include 'header.php';
?>
<section>
<div>
<p>misc. html</p>
</div>
</section>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
footer.php
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/includes/footerscripts.php');
?>
</body>
</html>
/includes/footerscripts.php
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<?php
$testVar = 'test';
?>
In that scenario, the index file does have this in the source code when ran:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
test =
The scripts are making their way there but are not being executed and the variables aren't coming through either.
When I change the footer.php to include those scripts and variable directly, the variable makes it to index.php, so do the scripts but they don't execute (or not on time?).
Any ideas guys?
I have a weird php5.ini file as I didn't know what all to put in it, if that makes a difference. The include file path seems okay as it still works for the most part.
Thanks,
Matt
Edit: Added the include ('header.php') which works fine and pulls in my header.
That file looks like:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="--">
<meta name="keywords" content="--">
<meta name="author" content="--">
<title>--</title>
<link rel="stylesheet" href="/css/mainstylesheet.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="icon" href="/images/favicon.ico">
</head>
<body>
<header class="nav-top" id="top" role="navigation">
<div class="container">
<div class="home-link">
<img src="/images/logo/logo-p.png" alt="plc" class="logo" />
</div>
<nav class="nav-main">
<ul>
<li>
Home
</li>
<li>
Portfolio
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Edit: Guess I just needed my jquery loaded from the header of the document, because it works that way. I still can't carry variables from grandchild to parent but oh well
According to your example the index.php file is missing something:
<?php
include ($_SERVER['ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
I assume that you didn't post the whole file, since here the output hmtl here is not valid - missing html opening tag, etc. Could you please provide the whole and/or simplified index file?
Replace all instances of $_SERVER['ROOT'] with $_SERVER['DOCUMENT_ROOT'].
The body of the base file has a include ' slider.php '.
In de slider.php there are css and javascript files that need to be load.
Because of the include it will but all of that in the body where the include is posted.
My question is: Is it possible if you have a include the file. You can say in the include put css and javascript in the <header> tag and not where the include is made.
[index.php]
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="slider">
<?php require_once( INCLUDES . 'slider.php');?>
</div>
</body>
</html>
[slider.php]
<?php
<!-- slider -->
<link rel="stylesheet" type="text/css" href="/normalize.css" />
<link rel="stylesheet" type="text/css" href="/demo.css" />
<link rel="stylesheet" type="text/css" href="/component.css" />
<script src="/slider.min.js"></script>
<script src="scattered_slider/classie.js"></script>
<div class="row header">
etc...
No, it's not possible to do that using only a single include/require.
The fastest solution would be to use two different files "slider_header.php" containing the javascript/css tags and "slider_body.php" containing the actual slider html.
Then you could include them like this:
<!DOCTYPE html>
<html>
<head>
<?php require( INCLUDES . 'slider_header.php');?>
</head>
<body>
<div id="slider">
<?php require( INCLUDES . 'slider_body.php');?>
</div>
</body>
</html>
Maybe you should consider using a proper template engine like Twig, but this requires a little bit more effort to set it up in the first place.
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
I'm trying to connect my PHP header from a file that is in a folder.
I'm attempting to do this by using:
<?php include("../header.php"); ?>
It works to bring the content in that file on the page, but its not applying the style.css file to the doc. Why?
Here is the contents of header.php:
<!DOCTYPE html>
<html>
<head>
<title>%TITLE%</title>
<link href='http://fonts.googleapis.com/css?family=Lilita+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="includes/normalize.css">
</head>
<body>
<header>
<div class="page-wrap">
<h2 id="logo">Some Company</h2>
<nav>
Home
Contact
Rentals
For Sale
</nav>
</div>
</header>
<section id="mainContent">
This is probably because its trying to reference the css at 'style.css' but try putting '../style.css'. It should allow the styles but it won't fix all your pages. In that case its better to use something like this:
<?php
// Set a constant with your url
define('BASE_URL', 'http://localhost:64411/TestingPHPStuff/');
echo 'Now use it in your html like this:';
?>
<link rel="stylesheet" type="text/css" href="<?=BASE_URL;?>style.css"/>
That way file location does not matter.
Basically though, you are trying to use a stylesheet that doesn't exist at that current level. Probably.
Edited
I changed it. If you include the 'http://' and the port ':64411' (for example you would use your port) then it should work. I just tested it and it only worked for me with both 'http://' and ':64411'.
I have a strange error on CakePhp 2.0 where the head tags renders empty, and all the tags that belongs to head, renders into the body before any content.
This his how the layout default.ctp looks:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->Html->charset(); ?>
<title>
<?php echo $title_for_layout; ?>
</title>
<?php
echo $this->Html->meta('icon');
echo $this->Html->script(array('librerias/jquery.tools.min'));
echo $this->Html->css('cake.generic');
echo $this->Html->css('webfront');
echo $scripts_for_layout;
?>
</head>
<body>
<div id="container">
<div id="header">
</div>
(the rest of the html render)
</body>
</html>
And this is how it's rendered, as firebug says:
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title> Usuarios </title> **(IE moves the title tag on the head manually, it seems)**
**(IE displays the DOCTYPE on its debugging console here)**
<link rel="icon" type="image/x-icon" href="/web/favicon.ico">
<link rel="shortcut icon" type="image/x-icon" href="/web/favicon.ico">
<script src="/web/js/librerias/jquery.tools.min.js" type="text/javascript">
<link href="/web/css/cake.generic.css" type="text/css" rel="stylesheet">
<link href="/web/css/webfront.css" type="text/css" rel="stylesheet">
<div id="container">
<div id="header"> </div>
(the rest of the html render)
</body>
</html>
It's bad enough because it distorts the DOCTYPE tag and makes IE render the page very buggy.
Also, I have another test site where it doesn't happen this error. In fact I switched layouts and the error was the same.
Does someone knows why this happens? I couldn't find anything similar on the web and I don't have any clue about this. Any help will be appreciated.
Thanks in advance
Finally we got the answer for this problem. It was Cake's php and the infamous character  that appeared on utf-8 encoding. By changing every encoding on php files that passed before the final layout, we solved the problem.
Thanks for your help :)
you have file with BOM char . use BOM Detector program
java : http://www.javapractices.com/topic/TopicAction.do?Id=257 [recommended][find and remove]
1- check URL for exist BOM
2- remove BOM from your file
php : http://www.dotvoid.com/2010/04/detecting-utf-bom-byte-order-mark/
You are missing one end tag in the layout file.
<body>
<div id="container">
<div id="header">
</div>
(the rest of the html render)
</body>
</html>
It should be corrected as follows
<body>
<div id="container">
<div id="header">
</div>
(the rest of the html render)
</div>
</body>
</html>