kvnirvana Posted November 14, 2010 Share Posted November 14, 2010 I've got this on my page index.php $rand = $_SESSION['rand']; if (empty($rand)) { srand((float)microtime()*1000003); $rand = rand(); $_SESSION['rand'] = $rand; } On all my other pages i've got this <?php unset($_SESSION['rand']) ?> The problem is that if I go to any other page than index it will unset the session 'rand'. If I then go back to index.php I get this error 'Notice: Undefined index: rand' is there a way to get around this? Link to comment https://forums.phpfreaks.com/topic/218654-undefined-index/ Share on other sites More sharing options...
marcus Posted November 14, 2010 Share Posted November 14, 2010 You're trying to give a variable the value of something nonexistent. You should try something like: $rand = (isset($_SESSION['rand'])) ? $_SESSION['rand'] : '';[code=php:0] Link to comment https://forums.phpfreaks.com/topic/218654-undefined-index/#findComment-1134112 Share on other sites More sharing options...
kvnirvana Posted November 14, 2010 Author Share Posted November 14, 2010 Thanks :=) Link to comment https://forums.phpfreaks.com/topic/218654-undefined-index/#findComment-1134127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.