Well, I am currently trying to write code which checks if a twitch stream is live or not. To do so I have created the array $_SESSION['errors']; On the second .php $_SESSION['errors'] is either given 'live' or 'Not live', however whenever it goes back to the first .php page the $_SESSION['errors'] will be overwritten at the point it was defined.
My question is, how, if possible would I get around this issue.
Code:
PHP in index.php:
<?php
$_SESSION['errors'] = '';
echo $_SESSION['errors'];
?>
PHP from streaminfo.php:
<?php
if (empty($_POST) === false) {
header('Location: index.php');
}
$streamer = $_POST['username'];
$apiurl = "https://api.twitch.tv/kraken/streams/" . $streamer;
$apicontent = file_get_contents($apiurl);
$streamerinfo = json_decode($apicontent);
if ($streamerinfo->stream == '') {
echo '<h2>' . 'Streamer is not live' . '</h2>';
$_SESSION['errors'] = 'not live';
header('Location: index.php');
}
?>
I realise that I am overwriting the array when index.php is loaded, however I must define it and I dont know what to define it with.
session_start();?