jeppers Posted August 11, 2008 Share Posted August 11, 2008 well made a simple script for a simple login nothing too hard. works fine on my local host but when i put on line. i just get the header infomation can not be sent. ect hear is my script <?php // script - login.php // this page lets people log in to the site include 'includes/header.php'; //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //set the page title and page header define ('TITLE', 'Login'); // basic html formatting stuff print '<h1>Simple Login Form</h1> <p>Please enter your user name and password.</p>'; //check if the form has been submitted. if (isset ($_POST['submit'])){ //handle the form if ((!empty ($_POST['username']))&&(!empty ($_POST['password'])) ){ if ( ($_POST['username'] == 'j')&&($_POST['password'] == 'p') ){ // okay //do session stuff $_SESSION['username'] = 'testing'; //redirect the user to the welcom page header ('location:welcome.php'); exit(); }else{//not ok print '<p>The submitted username and password do not match those on file!<br />Go back and try again.</p>'; } }else {//forgot a field. print '<p>Please make sure you enter both a username and a password!<br />Go back and try again </p>'; } }else{ // display the form (You can edit this just make) print '<form action="login.php" method="post"><p> Username: <input type="text" name="username" size="20" /><br /><br /> Password: <input type="password" name="password" size="20" /><br /><br /> <input type="submit" name="submit" value="submit" /><br /> </form>'; }// end of main conditional. //complete the html formatting stuff print '</div>'; ?> as you can see my header info is on lline 32 and i am just not sure how to change the location of this info or edit it so it works can anyone help please Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/ Share on other sites More sharing options...
Andy-H Posted August 11, 2008 Share Posted August 11, 2008 Take the closing php tag from includes/header.php let me know if it works (I read about it on php.net but it was a little confusing lol) Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613315 Share on other sites More sharing options...
waynew Posted August 11, 2008 Share Posted August 11, 2008 You seem to be printing to the screen BEFORE you're trying to redirect. // basic html formatting stuff print '<h1>Simple Login Form</h1> <p>Please enter your user name and password.</p>'; Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613316 Share on other sites More sharing options...
Dethman Posted August 11, 2008 Share Posted August 11, 2008 Try this: header('location: welcome.php'); Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613317 Share on other sites More sharing options...
waynew Posted August 11, 2008 Share Posted August 11, 2008 You can't print to the browser before redirecting or attempting to redirect. Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613318 Share on other sites More sharing options...
Dethman Posted August 11, 2008 Share Posted August 11, 2008 Sorry I had was making a post right as you posted forgot about that! Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613319 Share on other sites More sharing options...
jeppers Posted August 11, 2008 Author Share Posted August 11, 2008 Ok i see your points so how do you flush the header before redirecting Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613321 Share on other sites More sharing options...
waynew Posted August 11, 2008 Share Posted August 11, 2008 <?php // script - login.php // this page lets people log in to the site //include 'includes/header.php'; I blocked this out because I'm guessing it has the <HEAD> tags? //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //set the page title and page header //define ('TITLE', 'Login'); // basic html formatting stuff //print '<h1>Simple Login Form</h1> //<p>Please enter your user name and password.</p>'; //check if the form has been submitted. if (isset ($_POST['submit'])){ //handle the form if ((!empty ($_POST['username']))&&(!empty ($_POST['password'])) ){ if ( ($_POST['username'] == 'j')&&($_POST['password'] == 'p') ){ // okay //do session stuff $_SESSION['username'] = 'testing'; //redirect the user to the welcom page header ('location:welcome.php'); exit(); }else{//not ok print '<p>The submitted username and password do not match those on file!<br />Go back and try again.</p>'; } }else {//forgot a field. print '<p>Please make sure you enter both a username and a password!<br />Go back and try again </p>'; } }else{ // display the form (You can edit this just make) print '<form action="login.php" method="post"><p> Username: <input type="text" name="username" size="20" /><br /><br /> Password: <input type="password" name="password" size="20" /><br /><br /> <input type="submit" name="submit" value="submit" /><br /> </form>'; }// end of main conditional. //complete the html formatting stuff print '</div>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613322 Share on other sites More sharing options...
jeppers Posted August 11, 2008 Author Share Posted August 11, 2008 thanks waynewex that worked but i have to ask how would i get my css and functions in to the script Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613325 Share on other sites More sharing options...
jeppers Posted August 11, 2008 Author Share Posted August 11, 2008 sorry my question was a little vague. i mean to ask how will i get the header file within in the scrip with out producing that warning Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613327 Share on other sites More sharing options...
waynew Posted August 11, 2008 Share Posted August 11, 2008 The header will have to come after the attempted redirect. So, maybe a redesign is in the pipeline? Shouldn't take too much work. At least you know for future reference now. Quote Link to comment https://forums.phpfreaks.com/topic/119116-solved-i-am-sorry-but-i-am-baffled-headders-and-what-i-can-do-to-make-it-work/#findComment-613335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.