GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Aug-2008, 11:57
crazygol4 crazygol4 is offline
New Member
 
Join Date: Aug 2008
Posts: 10
crazygol4 is on a distinguished road
Unhappy

Header and Session errors


So I looked for a similar post on the forums and I couldn't find anything (don't really know what to type to find an answer). Here's the issue: I'm working on a user creation script to hook up with a MySQL DB. I've 3 pages in questions. They are show_adduser.php, do_adduser.php, and pageerror.php. Everything works fine but the lines of script I'm using to test if the inputed username already exists.

For some reason I have an issue between an echo and an if statement with a header redirect a few lines below (the echo shows how many similar results are in the DB.) I would like to still be able to see this on the do_adduser.php page, but it's not absolutely necessary. If I comment out the echo line, the do_adduser.php page redirects to show_adduser.php properly, but then for some reason DROPS $_SESSION[texliuser] and $_SESSION[texlipass] which allow the admin to access that page. SO, because these SESSIONS are dropped, it redirects to the pageerror.php page as it should. I have other SESSIONS that are being passed from do_adduser and do_showuser that show up just fine on the error page.

SO, I have two questions: 1) why is the echo producing this result:
Code:
6 Warning: Cannot modify header information - headers already sent by (output started at /home/content/username/html/example/reg/do_adduser.php:39) in /home/content/username/html/example/reg/do_adduser.php on line 44

2) Why are my SESSIONS being dropped when I have session_start() at the very beginning of each page?

Here is my code on all of these pages. I have replaced certain areas with [value] do_adduser.php:
PHP Code:

<?
session_start ();
require_once('[value]');

if (!$_SESSION[texliuser] || ($_SESSION[texlipass] != "[value]")) {
    $_SESSION[errorcode] = "d_add1";
    header( "Location: [value]/pageerror.php");
    exit;
}

if ($_COOKIE[auth] != "[value]") {
    $_SESSION[errorcode] = "d_add2";
    header( "Location: [value]/pageerror.php");
    exit;
}

if ($_SESSION[dynkey] != "[value]") {
    $_SESSION[errorcode] = "d_add3";
    header( "Location: [value]/pageerror.php");
    exit;
}

if ((!$_POST[u_accname]) || (!$_POST[u_pass]) || (!$_POST[u_email]) || (!$_POST[u_city]) || (!$_POST[u_state]) || (!$_POST[u_zip]) || (!$_POST[u_tosagree])){
    $_SESSION[errorcode] = "d_add4";
    header( "Location: [value]/show_adduser.php");
    exit;
}

$table_name = "[value]";

$db = @mysql_select_db($database_connTexli, $connTexli) or die(mysql_error());

$sql = "SELECT `user_accname` FROM $table_name WHERE `user_accname` = '$_POST[u_accname]'";

$result = @mysql_query($sql) or die(mysql_error());

$rows = mysql_num_rows($result);

//Below is Line 39 which causes error
echo $rows;

if ($rows >= "1") {
    //IF is yes, set a cookie message to change desired username.
    $_SESSION[errorcode] = "Username already exists.";
    header( "Location: [value]/show_adduser.php");
    exit;
}

//setting time of post
$acccreated = date("Y-m-d H:i:s");

$sql2 = "INSERT INTO $table_name (user_since, user_accname, user_pass, user_fname, user_lname, user_email, user_phone1, user_phone2, user_fax, user_website, user_addr1, user_addr2, user_city, user_state, user_zip, user_country, user_tos_agree) VALUES ('$acccreated', '$_POST[u_accname]', '$_POST[u_pass]', '$_POST[u_fname]', '$_POST[u_lname]', '$_POST[u_email]', '$_POST[u_phone1]', '$_POST[u_phone2]', '$_POST[u_fax]', '$_POST[u_website]', '$_POST[u_addr1]', '$_POST[u_addr2]', '$_POST[u_city]', '$_POST[u_state]', '$_POST[u_zip]', '$_POST[u_country]', '$_POST[u_tosagree]')";

$result2 = @mysql_query($sql2) or die(mysql_error());

$links = "
<P><a href=\"cntrconmgrtexlibw.php\">Go Back to Main Menu</a></P>";

?>


show_adduser.php:
PHP Code:

<?
session_start ();
require_once('[value]');

echo $_SESSION[errorcode];

#Notes: What username will admin posted ads show up under?

if (!$_SESSION[texliuser] || ($_SESSION[texlipass] != "[value]")) {
    $_SESSION[errorcode] = "s_add1";
    header( "Location: [value]/pageerror.php");
    exit;
}

if ($_COOKIE[auth] != "[value]") {
    $_SESSION[errorcode] = "s_add2";
    header( "Location: [value]/pageerror.php");
    exit;
}

if ($_SESSION[dynkey] != "[value]") {
    $_SESSION[errorcode] = "s_add3";
    header( "Location: [value]/pageerror.php");
    exit;
}

?>


pageerror.php:
PHP Code:

<? session_start(); ?>
<!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=iso-8859-1" />
<title>Page Error</title>
</head>

<body>
<? 
echo "<p><strong>";
echo $_SESSION[texliuser];
echo "<BR>";
echo $_SESSION[texlipass]; 
echo "<BR>";
echo $_SESSION[errorcode];
echo $_SESSION[errorcode2]; 
echo "</strong></p>";

$_SESSION[errorcode] = NULL;
$_SESSION[errorcode2] = NULL;
?>


I appreciate all help in advance!

Thanks,
Crazygol4
  #2  
Old 11-Aug-2008, 17:47
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Header and Session errors


See if the link within this post might be helpful.
The "headers already sent" can be caused by a few problems.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 12-Aug-2008, 19:15
crazygol4 crazygol4 is offline
New Member
 
Join Date: Aug 2008
Posts: 10
crazygol4 is on a distinguished road

Re: Header and Session errors


Sweet that makes a lot of sense of the first part...but why do you think it is dropping those particular $_SESSIONs and not the other ones?
  #4  
Old 13-Aug-2008, 20:21
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Header and Session errors


I found this at php.net within the postings under session_start():

Code:
The problem is some times the redirect may kick you off to the next page before all the session variables have been saved. The true solution to lost session vars on redirect is to simply call session_write_close(); before setting the redirect header. This will insure that php finishes writing the session info before page redirect gets underway. ie:
PHP Code:

<?
session_start();
$_SESSION['forward'] = "This session data will not be lost!";

session_write_close();
header('Location: nextpage.php');
?>

Not sure, but sounded relative based on what you've described.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #5  
Old 18-Aug-2008, 16:24
crazygol4 crazygol4 is offline
New Member
 
Join Date: Aug 2008
Posts: 10
crazygol4 is on a distinguished road

Re: Header and Session errors


Ahh perfect! That was the fix. Thanks a ton for the help!

-crazygol4
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Problem eRIC MySQL / PHP Forum 1 22-May-2004 23:40

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:19.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.