Directory subdirectory include file

/var/www/html/office is the location of most of my php files. beacue it got to messy I made a few directories,
/var/www/html/office/
/var/www/html/office/xxx/
/var/www/html/office/xyz/

I have a head.php file in /var/www/html/office/ which include java script for date&time

in the above script the time and date shows in all php fies in /var/www/html/office/ but not in /var/www/html/office/xxx/

changing to shows time and date in all sub directories but date time does not show in /var/www/html/office/ php files. I am confused, how do i make it univeral

no some of the java scripts which work in the …/office directory do not work in …/office/xxx directory.

How to make WHAT universal? Without having enough of your code that would be needed to reproduce the problem, no one can guess what’s wrong with your code. There are just too many different possible ways of doing things in programming, that without seeing actual code, there’s no way to narrow down the possibilities to just a few that can be investigated further.

As Phdr mentioned we are not clear on what you need help with. But, I will guess…
You mentioned folders with PHP files in them, so I will assume you are loading them dynamically based on some option…

So, normally, you would create a header for the page that would never change much. It would be the top-most part of your site. On this site, it is the part that shows the current topic and user info and then has a < HR > that separates it from the rest. And, that would be inside a PHP file called, let’s say header.php.
Then, the rest of the page would follow.
So, if you are including the files for the various offices, such as “xxx” and “xyz”, you should include the global header first. Something loosely like:
include (“header.php”);
include ("/office/xxx.php");

Or something similar… Not really sure what you are asking, but, hope this helps…

my header code is

<?php
session_start();
setlocale(LC_MONETARY, 'en_IN');
date_default_timezone_set('Asia/Kolkata');
$username = $_SESSION['username'];
$userlevel = $_SESSION['user_level'];
$full_name = $_SESSION['full_name'];
include "config.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" type="text/css" />
<head>
<header class="section header">
<?php
echo "<li style='text-align: right; padding:5px;'>USER: $full_name</li>";?>
<div style='text-align: right; padding:5px;'id="date_time"></div>
<script type="text/javascript" src="javascript.js"></script>
<script type="text/javascript">window.onload = date_time('date_time');</script>
<script>
</script>
</header>

the javascript file is in the same direcotry, the header shows name and date and time.

i also have a subdirectory say xxx,
the head.php file in this directoy shows only name but not the time.
the files in the subdirectory has
the include "…/head.php
however the header displays all data except the time&date.

if I change as follows:
script type=“text/javascript” src="…/javascript.js"></script
the data displays correctly in the subdirectory file, but the time & date (rest of the data shows) do not show!

Also files in the subdirectory have

<?php include "../head.php"; ?>

and files in the rood directory have

<?php include "head.php"; ?>

Well, so your problem is time not showing correctly? You are pulling the date_time from JS.
This means inside the user’s browser. Not sure if this is the best way to do it. A user can disable
JS from security reasons and then it would not be correctly displayed. You do not need any .js file
to run javascript. You also use date_time() function for the JS. There is no such function in JS.
I will guess you have that function created in the javascript.js file. Just one more complication…

Is there a reason you don’t just use PHP and display the time from the server? In PHP you can show the time using something like this: echo date(“Y-m-d H:i:s”); Well, this is U.S. format, but, easy to alter!
Then, you don’t need the javascript.js file, unless it contains other JS functions you have created.

As far as the pointers to files, the " …/ " in a src means back up one level of folders. Therefore, if you have your javascript.js file in one area and it does not change, you can use " / " to move to the root directory and then to wherever the .js file is. For example, I always put my JS code into a folder named lib and then inside another folder named js. So, to access it on my site it is always /lib/js to get to any of my JS code files. Most programmers keep libraries of some sort in a folder that is clearly marked. I like to have all of the support files in one folder and then group them inside that one. Any page in my site can get to /lib/js for JS files, /lib/incl for PHP includes, etc… But, it sounds like your issue is pointing to the correct folder for that one file.

Not sure if that helps, but, hope it does!

Sponsor our Newsletter | Privacy Policy | Terms of Service