I know this question has been asked before, but even after reading other posts I can't figure out whats going on...
Please have a look at my code structure and see what am I doing wrong..
Folder structure:
index.php
(FOLDER - Includes) header.php
(FOLDER - browse) blog.php , ecommerce.php, other.php
(FOLDER - core) init.php
I'm trying to include Header.php from includes folder in blog.php in browse folder. Below is my header.php code.
Header file located in Includes folder
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
<title>Web Awwards | Web Gallery | Submit your site</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- CSS
================================================== -->
<link rel="stylesheet" type="text/css" href="../css/base.css">
<link rel="stylesheet" type="text/css" href="../css/skeleton.css">
<link rel="stylesheet" type="text/css" href="../css/layout.css">
<link rel="stylesheet" type="text/css" href="../css/styles.css">
<link rel="stylesheet" type="text/css" href="../css/menu.css">
<link rel="stylesheet" type="text/css" href="../css/submission.css">
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Favicons
================================================== -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
</head>
<body>
<?php
require_once('core/init.php');
?>
<!-- Menu Horizontal -->
<div class="horizontal">
<div class="webName">
and Browse folder blog.php file code:
<?php
include './includes/header.php';
?>
<!-- TODO PHP Scripts -->
<div class="category nine columns">
<div class="category-img">
<img src="css/img/webImg/screen1.png" alt="Site Description"/>
</div>
<h3> Web Name </h3>
<h5> Designed By: Tautvydas Slegaitis </h5>
<h7> Designers url </h7>
<div class="vote">
<h4> Vote for my site </h4>
</br>
Love it
Nope, Not for me
</div>
</div>
</div><!-- Close Container Div -->
<div class="footer">
</div>
</body>
</html>
But it is not working. I dont know why,... Please please help me sort this out its killing me for the past 2 days. Coda 2 is showing me an error
" Warning: include(./includes/header.php): failed to open stream: No such file or directory in - on line 2 Warning: include(): Failed opening './includes/header.php' for inclusion (include_path='.:') in - on line 2 "
init.php code:
<?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'db' => 'webAwwards'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expire' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
// TODO Remove parenthesis in require once if doesnt work
spl_autoload_register(function($class) {
require_once('classes/' . $class . '.php');
});
require_once('/functions/sanitise.php');
?>
try :
include('../test/header.php');
it works fine in me.
Edit: and if not on your case, try to correct the path of your init.php:
require_once('../core/init.php');
You could try something like:
include $_SERVER['DOCUMENT_ROOT'] .'*/project_name_if_needed*/test/header/';
I don't know if this is recommended, so use with caution.
I had the same issue and finally discovered that OVH deactivates the option allow_url_include on their shared web servers by default. This is a general setting that can not be changed.
The solution is to use something like
require ($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
as Lucas said.
Related
I'm working on a Laravel project which uses Webflow's CSS framework rather than the default bootstrap framework. It works great for most pages, but I do have a 'profile' page where the CSS does not work at all. I found out it's because the route for the page uses a variable, it looks like this:
Route::get('/chum/{id}', 'App\Http\Controllers\ProfilesController#display');
The function:
public function display($id){
$users = User::findOrFail($id);
$following = $users->followings->count();
$followers = $users->followers->count();
return view('profile', [
'users' => $users,
'following' => $following,
'followers' => $followers
]);
As you can see you go to the URL along with the id of the user's profile and it should bring you there. But for some reason the fact that you're adding that variable to the end of the URL causes the CSS to not work at all. If it helps at all these are the stylesheets and javascript files I'm using in the boilerplate.
<!DOCTYPE html><!-- This site was created in Webflow. http://www.webflow.com -->
<!-- Last Published: Sun Nov 29 2020 00:43:15 GMT+0000 (Coordinated Universal Time) -->
<html data-wf-page="5fc2087d6594016e2f088aed" data-wf-site="5fc06e9787e537386fa53575">
<head>
<meta charset="utf-8">
<title>Profile</title>
<meta content="Profile" property="og:title">
<meta content="Profile" property="twitter:title">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="Webflow" name="generator">
<link href="css/normalize.css" rel="stylesheet" type="text/css">
<link href="css/webflow.css" rel="stylesheet" type="text/css">
<link href="css/cascade-ui.webflow.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js" type="text/javascript"></script>
<script type="text/javascript">
WebFont.load({
google: {
families: ["Courier Prime:regular,italic,700,700italic"]
}
});
</script>
<!-- [if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js" type="text/javascript"></script><![endif] -->
<script type="text/javascript">
! function(o, c) {
var n = c.documentElement,
t = " w-mod-";
n.className += t + "js", ("ontouchstart" in o || o.DocumentTouch && c instanceof DocumentTouch) && (n.className += t + "touch")
}(window, document);
</script>
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link href="images/webclip.png" rel="apple-touch-icon">
</head>
<body>
(Content would go here.)
<script src="https://d3e54v103j8qbb.cloudfront.net/js/jquery-3.5.1.min.dc5e7f18c8.js?site=5fc06e9787e537386fa53575" type="text/javascript" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="js/webflow.js" type="text/javascript"></script>
<!-- [if lte IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/placeholders/3.0.2/placeholders.min.js"></script><![endif] -->
</body>
</html>
You should change the path/url of your asset to root folder of your site. Maybe just need / at beginning. change
<link href="css/normalize.css" rel="stylesheet" type="text/css">
<link href="css/webflow.css" rel="stylesheet" type="text/css">
<link href="css/cascade-ui.webflow.css" rel="stylesheet" type="text/css">
to
<link href="/css/normalize.css" rel="stylesheet" type="text/css">
<link href="/css/webflow.css" rel="stylesheet" type="text/css">
<link href="/css/cascade-ui.webflow.css" rel="stylesheet" type="text/css">
or you can also change with asset helper function of laravel to add your full URL of the current host. like
<link href="{{asset('css/normalize.css')}}" rel="stylesheet" type="text/css">
{{asset('css/normalize.css')}} will be https://yourhost.com/css/normalize.css
I'm trying to create my new own theme for wordpress (and the first one) and I encounter that my site isn't loading the header nor the content of index.php. It's pretty strange, I've read the WP WSoD documentation but I couldn't find anything helpful since my theme only have a couple of lines, I don't see the problem.
This is my theme structure:
And I've only edited index.php, header.php and footer.php. My functions.php seems to have something but I just added some lines to test, it's now blank again.
And this is what's inside my header.php:
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title> <?php bloginfo( 'name' ); ?> </title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="<?= get_template_directory_uri() ?>/assets/css/bootstrap.min.css">
<!-- Natural Stylesheet -->
<link rel="stylesheet" href="<?= get_template_directory_uri() ?>/style.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="<?= get_template_directory_uri(); ?>/assets/img/favicon.png"/>
</head>
<body>
This is what's inside my footer.php:
<script type="text/javascript" src="<?= get_template_directory_uri(); ?>/assets/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="<?= get_template_directory_uri(); ?>/assets/js/popper.js"></script>
<script type="text/javascript" src="<?= get_template_directory_uri(); ?>/assets/js/bootstrap.min.js"></script>
</body>
</html>
And this is what I've inside my index.php:
<?php get_header(); ?>
<?php while( have_posts() ) the_post(); ?>
<?php get_footer(); ?>
I edited index.php and WordPress was loading front-page.php
I have a little template and in this template I have a query from database.
The name of the page is test.php and the code is:
This is the main page where i echo the content is named test.php
<?php include "components/header.php"; ?>
<div class="container">
<!-- Jumbotron -->
<?php
if (isset($_GET['user']))
{
$user = $_GET['user'];
}
else
{
die("Not found");
}
$result = mysqli_query($con, "SET NAMES utf8");
$query = "SELECT * FROM users WHERE fk_music=".$user;
$res = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($res);
echo $row['text'];?>
</div>
<?php include "components/footer.php"; ?>
Now with the echo $row['text'] I have to echo all the content from the page, and in header.php are the data like <html><header><title></title></header> etc. How can I put a title foreach data from database dynamic?
There is the code from header.php
<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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>???</title>
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link rel="stylesheet" href="/css/media-queries.css">
<link rel="stylesheet" href="/style.css">
<!--Hover categorii -->
<script src="/js/hover.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="/../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
Now in database i have two rows id of the post and the row named text where is stored the HTML of all the page
Here is an example with content existing in row['text']
<p class='style-title'>HERE IS THE THE TEXT I WANT TO PUT IT IN <title> </p>
<div class='jumbotron'>
<img class='img-responsive' src='/img/img.png'/>
</div>
<div class='row'>
<div class="col-lg-10 ">
<img class='img-responsive' src='/img/50.png' align='left' />
<p class='some-class'>Lorm ipsum</p>
My website loads perfectly on Firefox, but the CSS disappears completely on Chrome (although the html loads).
According to the console, this seems to be because Chrome is loading the contents of index.php into main.css and bannerTest.css like so:
On Firefox, however, it loads the CSS as expected:
Things I have tried that did not work:
clearing my history/cache/cookies
adding text/css to the tags. All this did was make the text render a
little weirdly on Firefox.
css and html validation. I fixed all the semi-colons and such. Still doesn't work.
What's the problem? I can't even figure out what steps to take to investigate what's going on more deeply, let alone figure out the problem itself. No errors are printed to the console as far as I can tell.
Here is index.php:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Study</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bannerTest.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<style>
/**
* The banner assumes a margin of 0px, but is not included
* in banner.css to avoid collisions with other themes and
* admin bars.
*/
body {
margin:0px;
}
</style>
<link rel="icon" type="image/ico" href="favicon.ico">
</head>
<body>
<?php
//Connect to MySQL database.
$host = "127.0.0.1";
$user = "root";
$password = "password";
$database = "database";
$r = mysql_connect($host, $user, $password);
if (!$r) {
echo "Could not connect to server.\n";
trigger_error(mysql_error(), E_USER_ERROR);
}
$query = "CREATE DATABASE IF NOT EXISTS " . $database;
mysql_query($query);
#mysql_select_db($database) or die("Unable to select database.");
$query="CREATE TABLE IF NOT EXISTS `groupcodes` (`groupcode` int(10) PRIMARY KEY, `usercode` int(10))";
mysql_query($query);
$userid = "";
?>
<div id="banner">
<div id="u-header-container">
<div class="container">
<div class="row-fluid">
<div id="home-link-container">
<a id="home-link" href="http://csue.edu/">
<span id="wordmark">U</span>
<span id="university">UNIVERSITY</span>
</a>
</div>
</div>
</div>
</div>
<div id="database-container">
<header>
<a href="index.php">
<h4 id="logo">Computing Systems</h4>
<h1 id="study_logo">Study</h1>
</a>
</header>
<div id="study">
<form method="post" id="consent-form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="wide-column">
<p>
By clicking the 'Acccept' button below, you hereby acknowledge the following:
</p>
<p>
I am 18 years of age or older, live in the United States, and have a Google Drive or Dropbox account.
I have read this form and decided that I will participate in the project described above.
Its general purposes, the particulars of involvement, and possible risks and inconveniences have
been explained to my satisfaction. I understand that I can withdraw at any time.
</p>
</div>
<input type="text" name="email_input">
<br>
<input type="submit" value="Begin Study">
</form>
</div>
</div>
</div>
</body>
</html>
You misdiagnosed the problem. It is due to visiting different URLs to load the HTML document rather then using different browsers. You just switched browsers at the same time as you switched URLs.
Look at the URL that is being loaded in your first image:
http://localhost/peergroup/index.php/css/main.css
In Chrome you must be visiting http://localhost/peergroup/index.php/ while in Firefox you are visiting http://localhost/peergroup/index.php (without a / at the end).
This is causing relative URLs to be computed differently.
A workaround is to use URLs that are relative to the site root (i.e. starting with a /).
I'm converting a couple sites from HTML to PHP for dynamic elements and have been able to do so with the header and footer (using php include()). However, I'm confused on how to do the head section. This is what I have with plain HTML:
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="Liberty Resource Directory. The ultimate curated directory to find what you need."/>
<meta name="keywords" content="ethan glover, lrd, liberty resource directory"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title>Liberty Resource Directory</title>
</head>
I can easily add the HTML5Shim script, meta charset, viewport (yes I will remove that max scale), and the stylesheet link.
Here's the problem:
How can I write the .php file in a way that I can pass an individual pages description, keywords and title to it? (That way I can put the entire above code in a php file and just include it on every page.)
Or will I simply have to exclude the description, keywords and title, and rewrite those parts every time?
Here's the answer: (Courtesy of Alejandro Arbiza)
head.php
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="<?php echo $description;?>"/>
<meta name="keywords" content="<?php echo $keywords;?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title><?php echo $title;?></title>
</head>
index.html (to include above code)
<?php
$description="Liberty Resource Directory. The ultimate curated directory to find what you need.";
$keywords="ethan glover, lrd, liberty resource directory";
$title="Liberty Resource Directory";
include 'scripts/head.php';
?>
The final result:
http://libertyresourcedirectory.com/
You can use variables for the description and the keywords (or anything else you want for that matter). Then, when the time comes to construct the page, you would just set the variables with the corresponding values.
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="<?php echo $description; ?>"/>
<meta name="keywords" content="<?php echo $keywords; ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title>Liberty Resource Directory</title>
</head>
So, lets say you have page1.php and page2.php:
<?php
// page1.php
$description = "This is page one";
$keywords = "page one";
include 'header.php';
?>
<!-- Page content -->
<?php include 'footer.php'; ?>
and
<?php
// page2.php
$description = "This is page two";
$keywords = "page two";
include 'header.php';
?>
<!-- Page content -->
<?php include 'footer.php'; ?>
Of course, I am assuming here that the whole HTML header is inside the header.php file, that is including <html>, <head> and <body>.