Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6036597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:56:52+00:00 2026-05-23T05:56:52+00:00

Today I learned for the first time how to create a simple login system

  • 0

Today I learned for the first time how to create a simple login system (with thanks StackExchange tips and THIS TUTORIAL. What i’m trying to do is use the PHPExcel framework to generate an Excel file ONLY for those who successfully login.

I’ve gotten very close, however I’m getting a crazy message about headers and below that is a bunch of jargon mixed up text.

Warning: Cannot modify header information - headers already sent by (output started at     /home3/mydir/public_html/d23/members/loggedin.php:6) in     /home3/mydir/public_html/d23/members/create_excel.php on line 92

Warning: Cannot modify header information - headers already sent by (output started at      /home3/mydir/public_html/d23/members/loggedin.php:6) in     /home3/mydir/public_html/d23/members/create_excel on line 93

Warning: Cannot modify header information - headers already sent by (output started at /home3/mydir/public_html/d23/members/loggedin.php:6) in /home3/mydir/public_html/d23/members/create_excel on line 94
ÐÏࡱá;þÿ       þÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

I know that the error is coming from these lines in the “create_excel.php” file, because when I comment them out, there is no error. But there is also no excel file creation.

 header('Content-Type: application/vnd.ms-excel');
 header('Content-Disposition: attachment;filename="userList.xls"');
 header('Cache-Control: max-age=0');

I will outline my process step by step- i’m a beginner so I bet this is stupidly easy for someone.

STEP #1 (login.php)

Calls the “process_login.php” file to authenticate the password typed into the form.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login Please</title>
</head>

<body>

<form action="process_login.php" method="post">
Password: <input type="password" name="password" /><br />
<input type="submit" value="Login" />
</form>

</body>
</html>

PAGE 2 (process_login.php)

If everything is fine,it will now re-direct you to “logged_in.php”, if not- you will get a denied message.

mysql_connect($host, $user, $pass);
mysql_select_db($database);


//$username = mysql_real_escape_string($_POST['username']);
$username = "person";
$password = hash('sha512', $_POST['password']);

$result = mysql_query("SELECT * FROM $table WHERE password = '$password'
");


if(mysql_num_rows($result))
{
  // Login
  session_start();
  $_SESSION['username'] = htmlspecialchars($username); // htmlspecialchars() sanitises     XSS
  // Redirect
header('Location: loggedin.php');
exit;
}
else
{
  echo '<p><strong>Error:</strong> Invalid username or password.</p>';
}
?>

STEP 3 (logged_in.php)

Now we have been successfully logged in, with an approval notice as well as a request to run “create_excel.php” file.

<?php 
session_start();
if(isset($_SESSION['username']))
{
  // Logged in
  echo '<p>You are logged in as '. $_SESSION['username']. '.</p>';
   // require the PHPExcel file
require 'create_excel.php';

}
else
{
  // Not logged in
  echo '<p>You are not <a href="login.php">logged in</a>.</p>';
}
?>

STEP #4 (create_excel.php)

This is where the header problem happens. I’ve tried to put the session script on this page alone, but I get the same problem. I was thinking if it was pulled from the “logged_in” page everything would be fine- but no. (Currently if I access this page directly the Excel file is generated and downloaded no problem).

<?php
/** Error reporting */
error_reporting(E_ALL);

date_default_timezone_set('Europe/London');

/** PHPExcel */
require_once 'Classes/PHPExcel.php';


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                             ->setLastModifiedBy("Maarten     Balliauw")
                             ->setTitle("Office 2007 XLSX Test     Document")
                             ->setSubject("Office 2007 XLSX Test     Document")
                             ->setDescription("Test document for         Office 2007 XLSX, generated using PHP classes.")
                             ->setKeywords("office 2007 openxml     php")
                             ->setCategory("Test result file");


// Add some data
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');

// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A4', 'Miscellaneous glyphs')
            ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:56:53+00:00Added an answer on May 23, 2026 at 5:56 am
      echo '<p>You are logged in as '. $_SESSION['username']. '.</p>';
      // require the PHPExcel file
      require 'create_excel.php';
    

    There lies your problem. You’re sending output to the client and then you want to change the headers and do something else. It doesn’t work that way.

    Consider doing it like this:

      echo '<p>You are logged in as '. $_SESSION['username']. '.</p>';
       // link to the PXPExcel file
      echo '<a href=\'create_excel.php\'>To Excel!</a>';
    

    Or just output the excel file without the login message:

      require 'create_excel.php';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I learned this JavaScriptSerializer ser = new JavaScriptSerializer(); Foo foo = ser.Deserialize<Foo>(jsonSz); I
I just learned about XLST on stackoverflow today (I love how in computers you
Just today learned that one of my websites, TwitPeek.net, is not rendering properly in
I've just today learned of asp.net mvc, and I'm wondering what is needed from
I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
I learned today that there are digraphs in C99 and C++. The following is
I learned today about the term invalidation in context of C++ containers. Can anyone
I've always called Connection.Close in the finally block, however I learned today you aren't
I learned Android's ArrayAdapter today, and find there is a commom pattern which uses
We just started PHP in my webscripting class today, and I'm already having problems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.