Hi, im trying to get my site to display username of user once they are logged in.
Something like: welcome “username” logged in.
LOGIN
[php]<?php
/* "Warning: Cannot modify header information - headers already sent by "
To avoid the header error , give value zero to
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0; */
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
ob_start();
if (isset($_POST[‘submitted’]) && !empty($_POST[‘myusername’]) && !empty($_POST[‘mypassword’]))
{
//check for submit button click
$username = $_POST[‘myusername’];
$password = $_POST[‘mypassword’];
// NOTE - quick check
$_SESSION[‘username’] = $username;
echo "Hello ".$_SESSION[‘username’];
// proceed with rest of code
$self = $_SERVER[‘PHP_SELF’];
$referer = $_SERVER[‘HTTP_REFERER’];
#if either form field is empty return to the log-in page
if( (!$username ) or (!$password ) ){ header( “Location:$referer” ); exit(); }
#connect to mysql
$conn = @mysql_connect( “removalspacecom.ipagemysql.com”, “removalspace”, “123” )
or die( “Could not connect” );
#select database
$rs = @mysql_select_db( “removalspacelogin”, $conn )
or die ( “Could not select db” );
#create query
$sql=“select * from users where username = '”. $username."’ and upassword = ‘".$password."’";
#execute query
$rs = mysql_query( $sql, $conn )
or die( mysql_error() );
if($rs){ $_SESSION[‘username’] = $username;}
#get number of rows that match username and password
$num = mysql_numrows( $rs );
#if there is a match the log-in is done
if( $num != 0 ){ header( “Location:login_success.php” ); }
else { header( “Location:$referer” ); exit(); }}
else {
?>
Username:
Password:
<? } ?>[/php]header location(login_success.php):
[php]<?php session_start();?><?php echo( $msg );?> // start up your PHP session! ?>
Home | Removalspace.com....................so on[/php]The thing to note here is the session start and php echo msg. This gives me headers already sent error message through browser? what would i need to do to get this right and ready?
Thanks…