Solved

2nd header not directing to thank_you page

Posted on 2003-11-30
6
202 Views
Last Modified: 2008-03-06
Hi there, I am trying to re-direct users to a thank you page.  But I get a header error because the code thinks that I have already sent a header as part of session variables and as such, cannot create another.  Can someone help me with this problem?

----------------------------------------------------------------------------------------------
err
====
Warning: Cannot add header information - headers already sent by (output started at /home/4435/pebbles/www.sixoone.com/public_html/biz/dev/add_card2.php:22) in /home/4435/pebbles/www.sixoone.com/public_html/biz/dev/add_card2.php on line 109

code
===

<?php
session_name();
session_start("first_name");
session_start("last_name");
session_start("cust_num");
session_start("username");
session_start("email");
if ((!(session_is_registered("first_name")))||
    (!(session_is_registered("last_name")))||
     (!(session_is_registered("cust_num")))||
     (!(session_is_registered("username")))||
     (!(session_is_registered("email"))))
{
session_unset();
session_destroy();
$url = "Location: re_userlogin.php";
header($url);     -------- header 1
}
else
{
echo "<b>Hello $first_name $last_name, you are Customer No. $cust_num, you are logged
in.</b>";
}
?>
<?php
//brians code start here
include "functions.inc.php";
include "error_messages.inc.php";

//action=add means usr pressd the submit button
if ($action =="add")
{
 $error_found=false;
 $error="";
 //start validating the user input
 }
 if($co_name=="")
 {
  $error_found=true;
  $error.=ERR_CO_NAME_BLANK;
 }
 if($inda=="")
 {
  $error_found=true;
  $error.=ERR_INDUSTRY_BLANK;
 }
 if($position=="")
 {
  $error_found=true;
  $error.=ERR_POSITION_BLANK;
 }
  if($equip=="")
 {
  $error_found=true;
  $error.=ERR_EQUIP_BLANK;
 }
if(!$error_found)
{
 $db_name = "afa";
$table_name = "_089";
$connection = @mysql_connect("mysql", "ps", "nro") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "insert into $table_name(
       email,
         co_name,
         inda,
         other,
         url,
         position,
         hours,
         cost,
         equip,
         web_source,
         username,
         cust_num,
         agent,
         status,
         date_reg,
         type)
         values(
             \"$email\",
             \"$co_name\",
             \"$inda\",
             \"$other\",
             \"$url\",
             \"$position\",
             \"Open all year Round\",
             \"Available on Request\",
             \"$equip\",
             \"bizafrican\",
             \"$username\",
             \"$cust_num\",
            129,
             \"active\",
             curdate(),
             \"client\")";
$result = mysql_query($sql,$connection);
$sql1 = "update _089 set inda = \"089\" where inda = \"_089\" ";
$result1 = mysql_query($sql1,$connection);

Header("Location: do_089xx.php");  -------- header 2  -- not working
exit;
}
else
{
 $error=ERR_HEADER.$error;
}
?>
0
Comment
Question by:Senyonjo
6 Comments
 
LVL 5

Accepted Solution

by:
arjanh earned 125 total points
ID: 9845255
You cannot do the
echo "<b>Hello $first_name $last_name, you are Customer No. $cust_num, you are logged in.</b>";

and then later on set a Location: header. Try removing that echo bit.
0
 
LVL 1

Expert Comment

by:jares
ID: 9845314
arjanh is right. all the headers, cookies, session cookies and all that stuff must be sent BEFORE a single line of a text is echoed, oherwise they won't be sent.
0
 
LVL 2

Assisted Solution

by:mbeckman
mbeckman earned 125 total points
ID: 9937738
If you want to display content, then you should use a META refresh redirect or a JavaScript SetTimeout() redirect.  Either one will work, and you can just replace Header("Location: do_089xx.php"); with   <meta http-equiv="refresh" content="2; url='do_089xx.php'">   or    <script> setTimeout((window.location='do_089xx.php'), 2000)  ... both will forward the page after 2 seconds.

If you don't want to display any content on this page, place the function  ob_start(); at the top of your page.  This will enable output buffering and you can send all the content out to the screen that you want and still utilize headers.


- Matt
0
 
LVL 2

Expert Comment

by:sandoshvr
ID: 9948438
you can use

ob_start();

function. so that all headers are sent at once.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Finding (and replacing) text between two strings in Php 7 50
Append letter to end of string 4 36
WordPress website error - Unable to access website. 5 28
html input type 3 21
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now