Default php include on all pages [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
On my site I have overall header and footer that are being created by functions header() and footer(), accessible in overall.php file. All sites are based on the same template so it looks like following:
<?
include ("/overall.php");
header();
echo "<div>";
// content of site
echo "</div>";
footer();
?>
I am thinking about another solution - maybe make a function createsite($content):
<?
function createsite($content)
{
header();
echo "<div>".$content."</div>";
footer();
}
?>
so that it would be simplier to create new page (there will be more than hundred of them). What are your ideas? I have been thinking about something like default include of overall.php on all sites. I hugely prefer clear PHP over frameworks like symfony or zend.

You will probably end up doing the same thing all of the frameworks are also doing, which is having a single point of entry for all your pages which will include all the neccesary functions (such as those in overall.php) and then redirecting the user to whichever actual page they want to see by including that as well.
Keep in mind that what you're currently building is (or rather, will be) a very basic framework in its own right.

Related

Building a html, css & javascript pages for wordpress without php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So as the titles already states, is it possible to build a fully functioning wordpress page layout/theme using only frontend languages? And how will I incorporate it into wordpress without php?
Thanks!!!
Well no but you could certainly get away with using very little.
Just have
<?php get_header(); ?>
at the top of every page and
<?php get_footer(); ?>
at the bottom
A page named header.php with
<?php wp_head(); ?>
at the top and a page named footer.php with
<?php wp-footer();?>
at the bottom should get you going. From there just use html and javascript like normal.
HOWEVER this is leaving out 99% of the reasons to make a WordPress theme in the first place. It's a good place to start learning but if you want to make themes your gonna want to learn php.
This tutorial worked well for me.
https://www.youtube.com/watch?v=k7olvEeBM2I&index=3&list=PLpcSpRrAaOaqMA4RdhSnnNcaqOVpX7qi5
Good luck!

Best way to manage multiple php includes? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
With my current workflow, when I need to add a new CSS sheet or a new script to a 10 pages website, I need to do this 10 times. Same story if I need to rename one item in my navigation menu, or correct a typo in the footer.
That made me realize that I need to start learning PHP to handle that via includes, echo, etc.
Therefore my question is the following: is there a best practice to do this? (I guess this is relatively easy to implement a < ?php include 'header.php'; ?> and a < ?php include 'footer'; ?> but can become quickly messy when it comes to dealing with unique page title and descriptions, etc.
What are your suggestions?
Many thanks
If your building not object style PHP website using require_once seems just the proper way to achieve your goal. It's better than include because require spread all errors and _once only include it once (Even if there is an inclusion of the same file deeper in the including tree) :)
Elsewhere Assetic is library that handle exactly this :)

Making a web page from many php/html pages [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a web page which made up of three pages[Header, Content, Footer]. I have something like as follows in my code
<?php
if (session_status() == PHP_SESSION_NONE){
session_start();
}
if(!isset($_SESSION['username'])){
include('header.php');
include('body.php');
include('footer.html');
}else {
header('Location: users.php');
}
?>
Is there anything wrong with this approach? Are I am doing the right thing? I am not facing any problems since I am a newbie So I am not much aware of the issues. I just want to know good/bad practice to achive this?
I have this kind of set up because header & footer is common for all my pages. So I just modify the centre portion.
For what you're trying to achieve, this approach is perfectly fine.
Although as your files and directories will increase in number, sometimes it'll get frustrating to remember the location of those files and using include accordingly. i.e. include("../../static_pages/body.php").
So you should put $_SERVER['DOCUMENT_ROOT'] at the beginning and use it accordingly to use the same URLs in whole websites.
i.e. include($_SERVER['DOCUMENT_ROOT']."static_pages/body.php")
Oh, mind the difference between require and include. require will stop execution when file is not found whereas include will just throw a warning.
Both have their importance. :D
I think there's nothing wrong with your approach. However, I am not a professional or something but if it works it should be alright because I think it is a secure way of displaying your page.

How to separate this PHP and HTML source [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have a change_username.php which makes it possible for users to change their username. If they changed their username a page like "Your new username ist xxx" or "xxx is already used" will be displayed.
I don't want to use an echo and put all the HTML stuff in there.
My first idea would be to create another 2 PHP's which then get the username from the change_username.php and display a proper result with HTML.
Are there any alternatives / better ways to do that? Creating files for every result sucks as much as putting the HTML data in an echo.
If I understood your question correctly you want to include a page with in your PHP: try using this as reference http://www.w3schools.com/php/php_includes.asp
You can include the page using
include 'filename';
or
<?php include 'menu.php'; ?>
I hope this helps you
I would do it a little bit differently, I think the problem is with managing the code where large page is getting messy. What I do in these cases I just use functions with parameters. So I create a lib.php file, where I store function with HTML blocks of code being echoed. Then when I need I call these functions in the necessary files, just requiring lib.php at the top of my page.

separating header and footers into their own files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Question: I've read a lot of tutorials/books that have taught putting the header and footers into their own files and using php to include them in the content pages.
However, if you have javascript running in those headers or footers- isn't this "bad" design- or does it not really matter?
I guess I take out the javascript if it's not needed for a page and I don't really mind CTRL+C. However I can see the usefulness and efficiency of making a change in only one file instead of all of them.
You should start using some template engine instead. Something to start with: Twig and Smarty
The most important feature you will like is called Template Inheritance
I would always separate your header and footer files out, it is a nightmare otherwise!
Just load in the JS when you need it, if using PHP just check the $_SERVER vars - http://uk.php.net/manual/en/reserved.variables.server.php

Categories