Hello. I am having a hard time trying to figure out how to structure my code inside pages, what to include and where. Basically I have a typical html page with a form in it. I also have a php file, that checks for sessions, and along this I have header.html, and menu.html
My form page looks like this:
<html>
<head> here I have some files linked that I would like put them in a file and include them on the pages i need. Should I put them in a html file and include them in every head page where I need them?
</head>
</body>
</html>
This if my php session file, where I check for sessions:
session_start();
if (isset($_SESSION['session_user_first_name']))
{
if( isset($_SESSION[‘last_acted_on’]) && (time() - $_SESSION[‘last_acted_on’] > 60*5) )
{
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
header('Location: index.html');
}
else
{
session_regenerate_id(true);
$_SESSION[‘last_acted_on’] = time();
require_once ('database_initialisation.php');
}
}
I also have some php code that would need to be executed on this html page:
I have been struggling with this files to make them work together, and I would really be grateful if you guys could help me a bit understanding how would be best to put them together.
What should I put in the head, what in the body, and also where should I check for the session?
Let’s say your session file is called sessions.php, and that final PHP snippet you gave will be given from another page right? This should be what you use
<?php
include "sessions.php"
?>
<html>
<head> here I have some files linked that I would like put them in a file and include them on the pages i need. Should I put them in a html file and include them in every head page where I need them?
</head>
<body>
$u_password = $_POST['passwordInput'];
$u_name = $_POST['nameInput'];
$u_l_name = $_POST['surnameInput'];
..... more code ...
$admin_query->addEmployerData($u_password, $u_name, $u_l_name, $u_DOB, $u_address, $u_email, $u_phone, $u_gender, $u_position, $u_contract_type, $u_contract_hours);
</body>
</html>
Ok. Cool, so session file is right at the top before HTML. And for the header, and menu? Body, right?
And the PHP that I will be using for this page include from another file. At the top, or in the body?
That sessions file must be at the very top since you are also using PHP headers. Headers cannot be used once content is given to the browser so it needs to be at the top.
So yes, sessions/headers should be before anything else on your page. Thus, at the top of your file.
Why are you loading those pages before <body>? Include function in PHP will basically copy/paste whatever file you are loading, and put it into your page.
So get a regular page working without PHP includes
Then when that works, cut/paste a section of code into a PHP include file (menu.php for example) and EXACTLY WHERE YOU CUT/PASTE the file, put <?php include "menu.php"?>
Think of PHP includes as copy/pasting whatever is in that file and putting it into the new file.
Thinking of this, can you honestly say what you are doing is valid? No. Not close .
What is this? Is this your menu.html? If so, remove hte <?php and ?> at the top /end of the file
I siad PHP includes copy/paste whatever is in the file and put it in the main page. What you have in this code is invalid. All of that HTML is being parsed as PHP!!
I tried with and whiteout php before, still nothing…There is a lot of stuff there that i dont need, I know, but i didnt have the chance to take it out…
I don’t know where to check the errors…
This is actually the header or black bar at the top, has a lot of stuff that i don’t need, it was a theme from bootstrap.
Header:
<nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header">… and more stuff.
[10-Apr-2015 20:40:14 Europe/Berlin] PHP Notice: Use of undefined constant ‘last_acted_on’ - assumed ‘‘last_acted_on’’ in /Applications/MAMP/htdocs/mysqli/welcome_employer.php on line 5
[10-Apr-2015 20:40:14 Europe/Berlin] PHP Notice: Use of undefined constant ‘last_acted_on’ - assumed ‘‘last_acted_on’’ in /Applications/MAMP/htdocs/mysqli/welcome_employer.php on line 14
I used the code from post 15, and i still get just this…