PHP variable getting overwritten -


well, trying write code checks if twitch stream live or not. have created array $_session['errors']; on second .php $_session['errors'] either given 'live' or 'not live', whenever goes first .php page $_session['errors'] overwritten @ point defined.

my question is, how, if possible around issue.

code:

php in index.php:

<?php $_session['errors'] = ''; echo $_session['errors']; ?> 

php 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 not live' . '</h2>';                 $_session['errors'] = 'not live';                 header('location: index.php');             } ?> 

i realise overwriting array when index.php loaded, must define , dont know define with.

you can check if element empty, , if so, can define it.

index.php:

<?php session_start(); // have in file? if (empty($_session['errors'])) {     $_session['errors'] = ''; } echo $_session['errors']; ?> 

Popular posts from this blog