Hobittual Posted February 1, 2014 Share Posted February 1, 2014 I get this error message via email. <p>An error occurred in script '/home/content/48/8529948/html/kvw/56/login_success.php' on line 51: A session had already been started - ignoring session_start() I can see that I have session_start() in two places in the same php file <?phprequire_once ('verify.php');$page_title = 'Success';// Start output buffering:ob_start();// Initialize a session:session_start();// Check for a $page_title value:if (!isset($page_title)) { $page_title = 'User Registration';}// If no first_name session variable exists, redirect the user:if (!isset($_SESSION['first_name'])) { $url = BASE_URL . ''; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. }?><!doctype html><html class="no-js" lang="en"><head><title>Nice one</title><meta charset="utf-8"><meta name="HandheldFriendly" content="True"><meta name="MobileOptimized" content="320"><meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="assets/css/style.css"><link rel="stylesheet" href="assets/fonts/raphaelicons.css"><link rel="stylesheet" href="assets/css/main.css"><link href="http://fonts.googleapis.com/css?family=Oswald:regular" rel="stylesheet" type="text/css"> <link href='http://fonts.googleapis.com/css?family=Junge' rel='stylesheet' type='text/css'> </head><body><header class="clearfix"> </div></header><section role="banner"><article class="succ"><?session_start();echo " Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."! You have made it to the members area!<br /><br />";echo "Your user level is ". $_SESSION['user_level']." which enables you access to the following areas: <br /><br>";if($_SESSION['user_level'] == 0){ echo "- <a href=index.php>KVW</a><br />- <a href=blog.php>CHAT</a><br />";}if($_SESSION['user_level'] == 1){ echo "- <a href=index.php>KVW</a><br />- <a href=blog.php>CHAT</a><br />- Moderator Area<br />";}echo "<br /><a href=logout.php>Logout</a>";?> </article></section> I can see what is wrong, but which one do I remove? Hope this is enough. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 1, 2014 Share Posted February 1, 2014 I always put that line at or near the beginning of my scripts. Quote Link to comment Share on other sites More sharing options...
Hobittual Posted February 1, 2014 Author Share Posted February 1, 2014 TBH I am a cut and paste man so I can't adapt this with any confidence. So I should leave the first one in? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 1, 2014 Share Posted February 1, 2014 In that case you should just leave it all alone. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 1, 2014 Share Posted February 1, 2014 The error message says that the second session_start() isn't doing anything. So the script should be fine once removed. Also note that session_start() needs to be called before anything is outputted to the browser. So if the second session_start() was activated, you would get a different error. More information about session_start() can be found here: http://www.php.net/session_start If you're worried about breaking something (or even if you're not), it's a good idea to save a copy of the original working code. That way you can always revert back if needed. Quote Link to comment Share on other sites More sharing options...
Hobittual Posted February 1, 2014 Author Share Posted February 1, 2014 Thanks cyberRobot. It all makes sense now, sort of. I deleted the second entry and so far no error messages. Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.