Question: I have a php webpage and this prints html commands and do something else. I have a div section:

```
<div id="monitor" class="monitoring"><?php include "php/monitoring.php"?></div>

```

This script in the index.php script should be called every 60 seconds. So I found AJAX and JavaScript useful to do this. Therefore I use this script:

```
<script type="text/javascript">
window.setInterval(function () {executemonitor()}, 60000);

function executemonitor() {
    $("#monitor").load("php/monitoring.php");
}

```

The scripts works fine, but the problem is, that second run of the monitoring.php script fails. The script is not able to use the $\_SESSION variables. I get the error: **Notice: Undefined variable: \_SESSION in C:\xampp\htdocs\mi-hand\php\monitoring.php on line 168.**

If I use the html refresh command, it works. 

```
<meta http-equiv="refresh" content="n" />

```

But then the whole page is refreshed. I want to avoid this. I want only refreshing the div section, by executing the php script. How can I do this? The monitoring.php file is a separate HTML page.

Answer: 
the \_SESSION variable is available in php only after session\_start() has been called.

your client calls 2 different scripts :

* index.php which renders the div and includes monitoring.php
* monitoring.php which renders the content of the div

you have a session\_start() in index.php but not in monitoring.php so this cannot work when the client calls directly monitoring.php.

You could create a session.php file which does the session initialization (like calling session\_start()) and then in both index.php & monitoring.php use

```
include_once('session.php');

```

if you have php > 5.4 you could also add in monitoring.php the following code

```
if (session_status() == PHP_SESSION_NONE) {
  session_start();
}

```

Source: <http://php.net/manual/en/function.session-status.php>
If you are accessing `"php/monitoring.php"` directly, you need to use `session_start()` in the beginning of that script, not only in `index.php`.