Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2006, 12:14 PM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Login error: session_start()

Greetings,
I am getting the following error in my script, and through much research, I cannot find a solution.

Background:
- xp home
- apache2triad 1.5.4
- dreamweaver 8.0.1
- testing on local host with virtual host implemented and working
- some experience and technical savvy (maybe not;))

Trying to create an administrative login for my site using (primarily) a tutorial and information from Macromedia.

Here is the error I recieve:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at D:\apache2triad\htdocs\marketinginsider.ca\admin\l ogin.php:4) in D:\apache2triad\htdocs\marketinginsider.ca\admin\l ogin.php on line 6

php code begins on line 1, nothing is prior.
Code is as follows:
Code:
<?php include ('/Connections/connMI_local.php');        // connect to database?>
<?php ini_set ('display_errors', 1);                    //display all errors?>

<?php                                                    // *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "/admin/index.php";
  $MM_redirectLoginFailed = "/admin/login.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_connMI, $connMI);

  $LoginRS__query=sprintf("SELECT user_username, user_password FROM user WHERE user_username='%s' AND user_password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 

  $LoginRS = mysql_query($LoginRS__query, $connMI) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";

    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

?>
FYI include code is as follows (been suspecting error begins here):
Code:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connMI_local = "localhost";
$database_connMI_local = "marketinginsider";
$username_connMI_local = "root";
$password_connMI_local = "stock";
$connMI_local = mysql_pconnect($hostname_connMI_local, $username_connMI_local, $password_connMI_local) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
Many thanks and I look forward to a resolution - it has been way too many hours trying to resolved and troubleshoot.
 
Old April 25th, 2006, 05:59 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You says that Macromedia code .. roflmao nice >.> open the notepad *I love ya*
anyway: session_start(); must be on your 1st line of code.. you can't have
<?php include lets do 300 operations here ?> session_start();

so:
<?php include ('/Connections/connMI_local.php'); // connect to database?>
<?php ini_set ('display_errors', 1); //display all errors?>

<?php // *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}
should be:
<?php
session_start();
include ('/Connections/connMI_local.php'); // connect to database
ini_set ('display_errors', 1); //display all errors
?>
 
Old April 27th, 2006, 10:25 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the assistance.
In the end, I rewrote the entire code without using Dreamweaver's "helpers".
It all works great now!

My suggestion is - avoid dreamweaver's helpers. Use them as a starting point to learn, but your coding will be much cleaner on your own






Similar Threads
Thread Thread Starter Forum Replies Last Post
session_start() changusee2k PHP How-To 2 February 11th, 2006 05:32 AM
Warning: session_start(): khile Beginning PHP 3 August 16th, 2005 04:09 AM
Problem with session_start() jmrdeuce32 Pro PHP 5 June 10th, 2005 01:53 PM
Problem with session_start() jmrdeuce32 Beginning PHP 4 May 8th, 2005 05:09 PM
Problem with Session_Start() jmrdeuce32 PHP How-To 2 April 29th, 2005 12:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.