PHP errors i cant seem to fix..

Discussion in 'PHP' started by VsUK, Aug 8, 2009.

  1. #1
    Ok, ill keep it simple & hope you can figure out the problem..

    This is a website i created for use for a clan

    www.xeon.owlife.co.uk/aniaps/

    Now, the problems are this... When i click register, all looks fine. Then when i add an username & password all looks fine & it changes to login which was intended. However when you use same details to log in, im presented with this error..

    
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/owlife/public_html/xeon/aniaps/db.php:5) in /home/owlife/public_html/xeon/aniaps/checklogin.php on line 9
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/owlife/public_html/xeon/aniaps/db.php:5) in /home/owlife/public_html/xeon/aniaps/checklogin.php on line 12
    
    Code (markup):
    The code for checklogin.php is as follows...

    
    <?php
    	include("db.php");
    	$myusername = mysql_real_escape_string(stripslashes($_POST['username']));
    	$mypassword = sha1(mysql_real_escape_string(stripslashes($_POST['password'])));
    	$result = mysql_query("SELECT * FROM `aps_admins` WHERE username='$myusername' and password='$mypassword' UNION SELECT * FROM `aps_members` WHERE username='$myusername' and password='$mypassword'");
    	$count = mysql_num_rows($result);
    	if ($count == 1)
    	{
    		session_start();
    		$result = mysql_fetch_array($result);
    		$_SESSION['aps_session'] = $result;
    		header("location:/?score");
    	}
    	else
    	{
    		include("index.php");
    		echo "<div class=subitem>Wrong Username or Password";
    		include("login.php");
    	}
    ?>
    
    PHP:
    Now, when i backup, it shows im logged in..

    Now if i should click change password link, i get this error.

    
    
    Warning: include(changepw.php) [function.include]: failed to open stream: No such file or directory in /home/owlife/public_html/xeon/aniaps/index.php on line 29
    
    Warning: include(changepw.php) [function.include]: failed to open stream: No such file or directory in /home/owlife/public_html/xeon/aniaps/index.php on line 29
    
    Warning: include() [function.include]: Failed opening 'changepw.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/owlife/public_html/xeon/aniaps/index.php on line 29
    
    Code (markup):
    The index code is as follows...

    
    <?php
        session_start();
    	require("db.php");
    	if (isset($_GET['logout']))
    		include("logout.php");
    ?>
    <html>
    <head>
    <title>Animosity Aps</title>
    <link rel="stylesheet" type="text/css" href="my.css" />
    </head>
    
    <?php
    	include("header.php");
    	
    	if (isset($_GET['prices']))
    		include("prices.php");
    	else if (isset($_GET['log']))
    		include("log.php");
    	else if (isset($_GET['vault']))
    		include("vault.php");
    	else if (isset($_GET['login']))
    		include("login.php");
    	else if (isset($_GET['admin']))
    		include("admin.php");
    	else if (isset($_GET['register']))
    		include("register.php");
    	else if (isset($_GET['changepw']))
    		include("changepw.php");
    	else if (isset($_GET['score']) || empty($_GET))
    		include("score.php");
    ?>
    
    
    PHP:
    Now finely when i click logout i get this error..

    
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/owlife/public_html/xeon/aniaps/db.php:5) in /home/owlife/public_html/xeon/aniaps/logout.php on line 5
    
    Code (markup):
    The code for the logout.php is as follows..

    
    <?
    unset($_SESSION['session_name']);
    session_destroy();
    header("location:/?login");
    ?>
    
    PHP:
    Everything else seems to work fine but i just cant put my finger on it. I had a lot of help making this & i only recognise certain aspects of code & play about with it to get things working so im in no way pro. So if you could provide any help or with a fix highlighting the problem area's & with the corrected code that would be fantastic.

    Also sorry for the large post, i didnt really want to ask but it took me & a friend a long time to make this site & we cant get passed these errors.

    Thanks again.
     
    VsUK, Aug 8, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You cannot start a session or use header() if anything has been outputed to the browser , try making sure to place start_session() above anything else in the script.

    According to the error you're outputting something to the browser at roughly the 5th line of db.php
     
    kblessinggr, Aug 8, 2009 IP
  3. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    session_start(); has to be at the very top of the page. checklogin.php doesn't follow that as it sets after the if/$count. Starting or checking a session costs almost nothing so there's no harm in not keeping it under an if statement.

    edit: ahhh beat me to it kblessinggr :D
     
    Goramba, Aug 8, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well doesn't "have" to be at the very top, but you can't call it if an output to the browser has already occured (such as an echo or something other) the same rule for header(). If there is no output from db.php for example may need to just rewrite db.php to eliminate any white spaces outside of the php code.
     
    kblessinggr, Aug 8, 2009 IP
  5. VsUK

    VsUK Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    well my db code is this, with edits of course :D

    
    <?php
    mysql_connect('localhost', 'database_User', 'password') or die(mysql_error());
    mysql_select_db('database_name') or die(mysql_error());
    ?> 
    
    PHP:
    its same type of db used for other things without problems...
     
    VsUK, Aug 8, 2009 IP
  6. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's probably not the code itself, but rather a trailing white space after the ?> if you got a text editor that can show you invisibles, that might explain why you're getting output from the file.
     
    kblessinggr, Aug 8, 2009 IP
  7. VsUK

    VsUK Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok, i did that & found 1 space at the end & removed it. Uploaded & tried to log in & i got blank page with ?score. This is new to me lol
     
    VsUK, Aug 8, 2009 IP
  8. VsUK

    VsUK Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok, everything appears to work, however when logging in/out & other functions it loads to xeon.owlife.co.uk/?score even though the files & directory are in xeon.owlife.co.uk/aniaps

    but if i backup its submitted data or performed the actions requested.

    Any idea's why the white page after submitting info & how to make it just refresh page or not show plank white page??

    Edit..

    Figured i wont triple post :D

    ok, i think i narrowed it down a little. When i login & submit, im presented with xeon.owlife.co.uk/?login same if i logout.
    If i register i get ?score & if i use the admin functions i get the same.

    Now, you have got my index.php code with part of that function above, however this is my score.php file..

    
    <table width=150>
    <tr>
      <td><div class=subsection><strong>Member
      <td><div class=subsection><strong>APS
    </tr>
    <?php
    	$result = mysql_query("SELECT * FROM `aps_admins` UNION SELECT * FROM `aps_members` ORDER BY `APS` DESC");
    	while ($row = mysql_fetch_array($result))
    	{
    		echo '<tr>' . "\n";
    		if ($member == 2)
    			echo '  <td><div class=subitem><a href="?log&username=' . $row['username'] . '" class=link>' . $row['username'] . "</a>\n";
    		else
    			echo '  <td><div class=subitem>' . $row['username'] . "\n";
    		echo '  <td><div class=subitem>' . $row['APS'] . "\n";
    		echo '</tr>' . "\n";
    	}
    ?>
    </table>
    
    PHP:
    I just have no idea why it gives me a blank white page on submitting date, but i can go back 1 page & its worked.

    Really dont like asking for help but this is killing me lol.
     
    Last edited: Aug 8, 2009
    VsUK, Aug 8, 2009 IP