Getting username greet...

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 {
?>

<?php ini_set("display_errors","ON"); ?> Check-login <?php echo( $msg );?> Login

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…

Hi there,

This error means that you have some information that was sent to the browser before the session_start() command. session_start() is sent through the headers of a webpage therefor if the headers were already sent before this command, the error will display. To fix this, make sure that there is no whitespace or spaces before you call session_start() and make sure you aren’t including any script that output anything to the browser before the command. Fixing this should get rid of the error.

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service