Basically i have a php script that i use to log requests on my website.(ip/browser, etc) which is log.php, how can i include the log.php in my index.html so every time someone visits my website they also get "logged"? I have tried a couple of things and its way off than what i want to do.
Basically i want to include domain.com/log.php on my main page..
I tried so many things so far and nothing has worked, i think its really really simple but i can't make it work.
Any help is highly appreciated.
Sorry for my bad english, not my first language. I hope you can understand what i mean.
The include statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.
Here's an example:
<HTML>
<head></head>
<body>
<h1>Welcome to this page!</h1>
<p>Some text.</p>
<?php include ('footer.php'); ?>
</body>
</html>
You can really execute a php code in a html file, what you can do is create a php file called index.php from there create add your code 'logging' code and then render the content of your page.
example index.php
<?php
// your code for logging the request
echo <html>...</html>
?>
Related
I've been searching around for a good hour or so and haven't really found anything to answer my question.
The thing is, I understand how to make a page and do:
index.php
<?php
include 'head.php';
include 'nav.php';
include 'footer.php';
?>
But in my nav.php, I'm not sure how the works, and how to include different content pages within my index.php like: contact.php, registration.php, etc.
I don't know how make it so that if I were to click the "contact" navigation link for example, only the content would change, and I wouldn't have to make a whole separate HTML file like so: Contact
Hopefully I explained it good enough. If anyone can give me a reference or explain how to do this, I would greatly appreciate it. Thank you guys.
I quoted your answer, this is the line
I don't know how make it so that if I were to click the "contact"
navigation link for example, only the content would change, and I
wouldn't have to make a whole separate HTML file like so:
<a> href="bla.html">Contact</a>
it's not the way it should be, what i get from your question is, you wanted a full page is all the same
<?php include 'head.php'; include 'nav.php';
and only this content should be change, not the head, not the nav, nor footer.
include 'footer.php'; ?>
am I correct?
if it is what you wanted, you should place a php file whatever the name is, index.php would be better. and the link it self should be called with something that php can get it.
Contact US
and in your index.php, you also create a condition if else would be easier.
if($_GET['contact']){
place your html /php here
}
else if($_GET['about']){
place your html /php here
}
else{
include 'index.php';
exit();
}
I suggest you not to do this, everyone is now can do the code, but not the code architecture .
wish it help you to understand.
You need to use different views. I believe you are looking for a way to change the view using php. One way is to add the page id in the url like 'www.myweb.com/index.php?page=contact' and receive it as a $_GET['page']. I think this is the simplest way to change the view using php. And this is the index.php, put all the view file in the views folder.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<?php
include 'head.php';
include 'nav.php';
switch($_GET["page"]){
case 'contact':
include 'views/contact.php';
break;
case 'registration':
include 'views/registration.php';
break;
case 'chat':
include 'views/chat.php';
break;
}
include 'footer.php';
?>
</body>
</html>
this would be your nav.php;
<ul>
<li> Contact </li>
<li> registration </li>
</ul>
I have decided to build my site website from scratch, rather than using Wordpress, Magento or a bootstrap template.
I'm looking for a good guide to do so, Code Academy and w3schools are good for learning specific elements of HTML and CSS but I'm looking for a good guide for how to structure my site.
I am playing around with creating an index.php using e.g. to include all element of the page to make creating the individual pages of my site clean and more efficient that including the include for header and footer on each page.
One issue I am having is that I am struggling to understand how to include the different pages within the index.php. I have searched for this but I obviously am not finding the correct words to search for this as I'm struggling to find a decent answer. I think I need something along the lines of a wildcard so that I can say to call all html files within my pages folder so that all pages are using my index.php template.
Below is my index.php to help explain. Thanks in advance and apologies if this question is answered elsewhere on the site, I searched but did not find anyone else answering the same question!
<!DOCTYPE html>
<html>
<php include "head.html" ?>
<body>
<div class="container">
<php include "navigation.html" ?>
<div class="wrapper">
<php include pages/*.html ?>
</div>
</div>
</body>
<php include "footer.html" ?>
</html>
It looks to me like you are almost there. I am not sure of the syntax you are using works, but the code below is used in some of my sites to include a header:
<?php include('includes/header.php'); ?>
This means include the code in the file 'header.php' that is in the folder 'includes', which is on the same level as the file that is calling the code.
The result would be that the 2 files are merged in to one when the page is loaded, with the code from header.php being inserted in place of the line
<?php include('includes/header.php'); ?>
You need to pass variables in URL e.g index.php?page=home and then in your index.php file you shoud get that variable $page = $_GET['page']. Now in $page you have name of the file to include
<?php include($page.'.html') ?>
For now, I skipped security issues of that solution.
As the title says, is there a way to edit a portion of an entire site with one code or page? For example, if the bottom of every page of a site said "2014", is there a way in html or css to change every page of the site to say "2015" without having to do so manually to each individual page?
I understand this can be done in php, and I understand that a server can be configured for html to read php code. Are there any flaws to this method (perhaps the html page will load slower if it's configured to read php)? Are there any other ways to do this besides using php code?
Performance Concern:
You will not see any performance difference between having PHP render basic HTML and typing the HTML yourself.
The performance impact is only noticeable on HUGE PHP applications. And even then, it's still very fast.
What you ask is common practice. This is an example of what you can do.
Make a file called index.php and put this inside:
<!doctype html>
<html>
<head>
<!--Your head stuff-->
</head>
<body>
<header><?php require_once 'header.html' ?></header>
<section class="main_content"><h2>My Page!</h2></section>
<footer><?php require_once 'footer.html' ?></footer>
</body>
</html>
Make a file called header.html and put this inside:
<h2>This is my header</h2>
Make a file called footer.html and put this inside:
<h2>This is my footer</h2>
As you can see, the practice is to use any of the built-in PHP functions to include other files in your PHP file:
include 'some_file.php';
require 'some_file.php';
require_once 'some_file.php';
I think Dreamweaver can do this, with its find and replace entire website property
Assuming all pages have a CSS file in common, you can use the content CSS property of a pseudo element like before or after to control content across all pages.
For example:
#footer:before {content:'2015';}
<div id="footer"></div>
so here is a question that I shouldn't be having so much trouble researching, but I am. Basically I want to create a webpage that loads in a header and a side bar. The header is it's own file header.php and the sidebar is leftBar.php. The following code is my index page, yet I am failing to have these pages loaded. I believe it has something to do with a lacking css page. But I have not found anything useful to help me solve this problem. What I would like to do is have the leftBar.php display its text on the left side of the page and the header.php file at the top. Below is the linked pages.
index.php
<html>
<head>
<title>junk</title>
</head>
<body>
junk
<?php
include ('styles/header.php');
include ('styles/leftBar.php');
?>
</body>
</html>
leftBar.php
<html>
left
</html>
header.php
<html>
header
</html>
In your include files, just place the code snippet that you want to appear on the page where it's included. You certainly don't want extra <html> elements (etc.) included at various places on the page.
I have a similar setup myself for the menu bar of a test site.
I think you have unnecessary brackets around your include file paths.
index.php:
<?php
include 'menu.php';
echo "$MENU";
?>
menu.php:
<?php
$MENU = '<table class="mainmenu"><tr><td>Home</td></tr><tr><td>Useful-Sites</td></tr></table>';
?>
You don't need to declare html tag for header.php and leftBar.php. A php file should start with <?php and end with ?>. Try learning php first http://w3schools.com/php/default.asp.
trouble researching?
first page of google:
http://www.w3schools.com/php/php_includes.asp
http://www.tizag.com/phpT/include.php
http://php.about.com/od/tutorials/ht/template_site.htm
http://www.tutorialspoint.com/php/php_file_inclusion.htm
Please look at these pages, and then update your question if you have to.
I have some html files that are exactly the same, except for a little area where goes some text. And I was thinking if there was a way to save writing the same text in the 7 files.
I thought on a possible soluction, but I find it a bit messy:
I split the page in 2 parts, upper.php and lower.php:
upper.php
<html>
<head>
...
</head>
<body>
...
<div id=content>
lower.php
</div>
...
</body>
</html>
And then I write the different pages like this:
home.php
<? include "upper.php" ?>
Welcome to my webpage where I do random stuff.
<? include "lower.php" ?>
contact.php
<? include "upper.php" ?>
Contact me by sending an email to asdf#a.org
<? include "lower.php" ?>
etc..
I suspect that this is a very dirty way to do it, any other workaround?
That's how I do all my websites. Sometimes there'll be settings before the first include (such as to determine if the user must be logged in or not), but for the most part that's how I like to do things.
The only real issue is to make sure that you don't get mixed up if you have files in different folders. Other than that, you should be good.