Jump to content

Found the error now what?


Hobittual

Recommended Posts

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

 

<?php
require_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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.