Jump to content

Recommended Posts

Hi everybody, would you please help me with this problem? Any help would be appreciated. I tried to put this php code into HTML webpage, however, I got error messages as follows:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\SNYP websites\loggedin.php:5) in C:\wamp\www\SNYP websites\loggedin.php on line 77

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\SNYP websites\loggedin.php:5) in C:\wamp\www\SNYP websites\loggedin.php on line 77

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\SNYP websites\loggedin.php:5) in C:\wamp\www\SNYP websites\loggedin.php on line 89

 

Here is my php codes (It is strange that it works fine if I dont put it into a HTML web page)

 

<?php # loggedin.php

# User is redirected here from login.php.

session_name ('YourVisitID');

session_start(); // Start the session.

 

// If no session value is present, redirect the user.

if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) {

 

// Start defining the URL.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

$url = substr ($url, 0, -1); // Chop off the slash.

}

$url .= '/index.php';

header("Location: $url");

exit(); // Quit the script.

}

 

...

?>

Link to comment
https://forums.phpfreaks.com/topic/51913-please-help-me-with-this-session-problem/
Share on other sites

Sorry.  :) I did not express clear. I did change it to .php. What I want to do is as follows: 

 

Here are some of the codes:

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>Log out</title>

<style type="text/css">

<!--

.STYLE1 {

font-size: 12px;

font-family: "Times New Roman", Times, serif;

font-weight: bold;

color: #666666;

}

-->

</style>

</head>

 

<body topmargin="0" bottommargin="0" background="images/bg.gif">

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">

  ....

 

  <?php // - logout.php

 

session_name ('YourVisitID');

session_start(); // Access the existing session.

 

// If no session variable exists, redirect the user.

if (!($_SESSION['user_id'])) {

 

// Start defining the URL.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

$url = substr ($url, 0, -1); // Chop off the slash.

}

$url .= '/index.php'; // Add the page.

header("Location: $url");

exit(); // Quit the script.

 

} else { // Cancel the session.

$_SESSION = array(); // Destroy the variables.

session_destroy(); // Destroy the session itself.

setcookie (session_name(), '', time()-300, '/', '', 0); // Destroy the cookie.

}

 

 

// Print a customized message.

echo "<h1>Logged Out!</h1>

<p>You are now logged out!</p>

<p><br /><br /></p>";

 

?>

      .....

</table>

</body>

</html>

 

 

And the error messages are:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\wamp\www\SNYP websites\logout.php:5) in C:\wamp\www\SNYP websites\logout.php on line 77

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\wamp\www\SNYP websites\logout.php:5) in C:\wamp\www\SNYP websites\logout.php on line 77

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\SNYP websites\logout.php:5) in C:\wamp\www\SNYP websites\logout.php on line 89

 

Hi ryeman98, thank you.  :)  I put session_start() before <html> and <head>, and two error messages are gone. however, there is still have the other error message, it is as follows:

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\SNYP websites\logout11.php:9) in C:\wamp\www\SNYP websites\logout11.php on line 89

 

How can I sorted out this problem? :)

 

Thank you.  :) Here is the motified version. The orange color parts are the changes. And the red part is the problem code.

 

 

<?php

session_name ('YourVisitID');

session_start(); // Access the existing session.

?>

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>Log out</title>

<style type="text/css">

<!--

.STYLE1 {

  font-size: 12px;

  font-family: "Times New Roman", Times, serif;

  font-weight: bold;

  color: #666666;

}

-->

</style>

</head>

 

<body topmargin="0" bottommargin="0" background="images/bg.gif">

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">

  ....

 

  <?php // - logout.php

 

// If no session variable exists, redirect the user.

if (!($_SESSION['user_id'])) {

 

  // Start defining the URL.

  $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

  // Check for a trailing slash.

  if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

      $url = substr ($url, 0, -1); // Chop off the slash.

  }

  $url .= '/index.php'; // Add the page.

  header("Location: $url");

  exit(); // Quit the script.

 

} else { // Cancel the session.

  $_SESSION = array(); // Destroy the variables.

  session_destroy(); // Destroy the session itself.

  setcookie (session_name(), '', time()-300, '/', '', 0); // Destroy the cookie.

}

 

 

// Print a customized message.

echo "<h1>Logged Out!</h1>

<p>You are now logged out!</p>

<p>

 

</p>";

 

?>

      .....

</table>

</body>

</html>

 

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\SNYP websites\logout.php:5) in C:\wamp\www\SNYP websites\logout.php on line 89

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.