I have a page function.php and call this function in another page view.php but function not call properly
Here is the function.php code
<?php
function head1()
{
global $title;
<html xmlns="http://www.w3.org/1999/xhtml">
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>WhiteFlower| florida web design</title>
</header>
}
head1();
?>
Second php file
<?php
include "function.php";
head1();
?>
This is code of another file view.php
I am new in php so I cannot understand how it works properly
This page is showing error because you are have error in your function you should echo your html or return them you are writing like html in php block
your code
<?php
function head1()
{
global $title;
<html xmlns="http://www.w3.org/1999/xhtml">
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>WhiteFlower| florida web design</title>
</header>
}
?>
Replace with this
<?php
function head1()
{
global $title;
echo '<html xmlns="http://www.w3.org/1999/xhtml">
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>WhiteFlower| florida web design</title>
</header>';
}
?>
please let me know if your error is resolved or not and also attach a snapshot of error we will figure it out
Related
Title tag displayed as "untitled document" for a file(apparel.php) which is in a folder(fashion) but appears correctly for a file(login.php) which is not in a subfolder.
Here is the head section of apparel.php:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Apparel</title>
<meta name="viewport" content="width=device-width, maximum-scale=1.0,
initial-scale=1.0", user-scalable="yes" />
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<link rel="stylesheet" type="text/css" href="../bootstrap-3.3.7/css
/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/navbar.css" />
<script src="../js/navbar.js"></script>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js">
</script>
<script src="../bootstrap-3.3.7/js/bootstrap.min.js"></script>
</head>
Here is the head section of login.php:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login </title>
<meta name="viewport" content="width=device-width, maximum-scale=1.0,
initial-scale=1.0", user-scalable="yes" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7/css
/bootstrap.min.css">
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script src="bootstrap-3.3.7/js/bootstrap.min.js"></script>
</head>
Any help is really appreciated.
Header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/Contents/css/bootstrap.min.css" rel="stylesheet">
<link href="/Contents/fonts/css/font-awesome.min.css" rel="stylesheet">
<link href="/Contents/css/animate.min.css" rel="stylesheet">
<link href="/Contents/css/custom.css" rel="stylesheet">
<link href="/Contents/css/icheck/flat/green.css" rel="stylesheet">
<script src="/Contents/js/jquery.min.js"></script>
</head>
Login View
<body style="background:#F7F7F7;">
....Html...
</body>
</html>
Login Controller
<?php
class loginController extends CI_Controller {
public function login() {
$this->load->View("template/header");
$this->load->View("login_view");
}
}
?>
Content Folder is present in Root Directory. Below is the structure
When I check this in Browser....css and js files does not load. Kindly suggest the corrective action
Add base_url() for each links, like this,
link href="<?= base_url("Contents/css/bootstrap.min.css") ?>" rel="stylesheet">
Change it in all links.
I work with PHP includes, and I need to put HEAD information in one of them. Is this possible, or can I only put a HEAD section on top of the index.php?
I'm asking this because the PHP includes has queries which I need in order to get OG image data (for social media) into the head. For example: I have a file WEBSHOP.PHP and in this file there is a product with an image. I want that image to show on the timeline in FaceBook.
This is an example of my (shortened version) of index.php:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<? include webshop.php; ?>
</body>
This is an example of my (shortened version) of webshop.php:
<!-- some mysql query to get variables as $pic and $row->meta_title -->
<head>
<meta property="og:image" content="http://forteuitgevers.nl/images/boeken/<? echo $pic; ?>" />
<meta property="og:title" content="<? echo $row->meta_title; ?>" />
<meta property="og:description" content="<? echo $row->meta_des; ?>" />
<meta property="og:url" content="http://<? echo $_SERVER['HTTP_HOST']; ?>/<? if (!empty($url_array[1])) { echo $url_array[1]; echo '/' ; } ?><? if (!empty($url_array[2])) { echo $url_array[2] ; } ?>" >
</head>
<!-- some code to view the webshop item -->
You're going to have to change the structure of your PHP files a bit in order to get all the header tags into one <head> section. If you include the webshop.php file before you start generating your HTML output you can then access the PHP variables when you write the head section. Something like this:
index.php:
<?php include webshop.php; ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<meta property="og:title" content="<?php echo $row->meta_title; ?>" />
<!-- other meta tags using variables from webshop.php -->
</head>
<body>
<!-- print out HTML code from webshop.php -->
<?php echo $doc_body; ?>
</body>
Then in webshop.php you'll have to save any HTML output with output buffering so you can add it into the HTML code in the proper place. Something like this:
<?php
// sql queries to get data
ob_start();
?>
<!-- html code to show up in the body section to view webshop items -->
<?php
$doc_body = ob_get_clean();
?>
Check out the PHP.net manual page on Output buffering for more info on ob_start and ob_get_clean.
Yes you can. However this is bad style. And you are making your HTML wrong:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<? include webshop.php; ?>
</body>
this will lead into
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<head>
<meta property="og:image" content="http://forteuitgevers.nl/images/boeken/<? echo $pic; ?>" />
<meta property="og:title" content="<? echo $row->meta_title; ?>" />
<meta property="og:description" content="<? echo $row->meta_des; ?>" />
<meta property="og:url" content="http://<? echo $_SERVER['HTTP_HOST']; ?>/<? if (!empty($url_array[1])) { echo $url_array[1]; echo '/' ; } ?><? if (!empty($url_array[2])) { echo $url_array[2] ; } ?>" >
</head>
</body>
However HTML does not like that the head tag is inside of the body tag. But most browser will still show it correctly.
To be sure: Check your result with a HTML Validator.
Good afternoon everyone. I'm stuck on including a file that has all of my 'head' information in it. I wanted to break down my page so it's simpler and less complicated. in my index.php file i did this;
<?php
include 'Resources/includes/head.php';
?>
It finds the file and i know this because in dreamweaver when i go on my index page it comes up as a tab underneath it. However when i view my index page on the local server, it's as if none of the styles or scripts have been applied to the page. This is the code that my head.php file has in it.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="description" content="" />
<meta name="keywords" content=""/>
<link rel="shortcut icon" href="../images/design/icon.png" type="image/x-icon"/>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen"/>
<script src="../js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../js/scripts.js" type="text/javascript"></script>
</head>
You may try something like this by using a base path
<?php
$basepath="http://www.mysite.com/path_to_theme/";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="description" content="" />
<meta name="keywords" content=""/>
<link rel="shortcut icon" href="<?php echo $basepath; ?>/images/design/icon.png" type="image/x-icon"/>
<link rel="stylesheet" href="<?php echo $basepath; ?>/css/style.css" type="text/css" media="screen"/>
<script src="<?php echo $basepath; ?>/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php echo $basepath; ?>/js/scripts.js" type="text/javascript"></script>
</head>
ok so I've created this website and want to convert it to php just for fun. The website structure looks like any 'normal' web structure. like this:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body class="fish">
</body>
</html>
ok so i included from the head to the beginning of the body tag in header.php file. so header.php looks like this:- `
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body class="fish">`
now here is the problem. Each page should have it's own title, body class! and each page will also obviously have it's own meta description and content. How will I accomplish this guys? I was think of creating a function that base the meta description and body class on the page title. But is there a smatter way to accomplish this? Thanks
Either use a template engine or a MVC framework (such as CakePHP or CodeIgniter) which have template engines already incorporated in them.
Inside your header.php do something like this:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $_tpl['title'] ?></title>
<meta name="description" content="<?php echo $_tpl['meta_desc'] ?>">
</head>
<body class="<?php echo $_tpl['body_class'] ?>">
On your page, before you use include('header.php'), define the vars as follows:
$_tpl = array();
$_tpl['title'] = 'My Title';
$_tpl['meta_desc'] = 'My meta description.';
$_tpl['body_class'] = 'fish';
As others have said though, don't re-invent the wheel. You'd be better to investigate some of the already-established templating engines for PHP:
Smarty
RainTPL
You should be creating a template to do this if it will be dynamic. You have many options on how you with to pass the data, whether it be a database, an object, array, etc. It is really tough to generate the data based on the page title, unless you are using a very persistent format to title each page.
<head>
<meta property="og:title" content="<?= $values['title'] ?>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<?= $values['url'] ?>" />
<meta property="og:image" content="<?= $values['image'] ?>/>
<meta property="og:site_name" content="<?= values['name'] ?>"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="ROBOTS" content="NOODP">
<link rel="icon" type="image/png" href="<?= $values['image'] ?>" />
<title><?= $values['title'] ?></title>
<? if(isset($values['css'])) : ?>
<? foreach($values['css'] as $css) : ?>
<link href="/css<?= $css['data'] ?>" rel="stylesheet" type="text/css" />
<? endforeach ?>
<? endif ?>
<? if(isset($values['js'])) : ?>
<? foreach($values['js'] as $js) : ?>
<script src="/js<?= $js['data'] ?>" type="text/javascript"></script>
<? endforeach ?>
<? endif ?>
</head>