PC Nerd Posted January 28, 2007 Share Posted January 28, 2007 hi guys. im creating a login script..... basically going like:if ( errors, create relevent variable warning.)else(cookies and re;locate user)BUTbecauase im creating the variables, i think PHP thinks im creating output, it obvious;ly doesnt work..... ( header(); ) but ob_start() wont work because it would use the header information anyway, and basically relocate before validation........ this is my code.... does anyone have any ideas on how to do this... ( validate andthen relocate if neccisary.)[code]<?phpob_start();include("inc_files/Database_link.inc");$Error1 = "";$Error2 = "";$Error3 = "";$Error4 = "";if(empty($_POST['User_Name']) || empty($_POST['Password']) || empty($_POST['Valid'])) { $Error1 = "True"; $Error = "True";}require("inc_files/Login_Pics.inc");$img_post_valid = "B_A-Login_".$_POST['IMG_Valid'];$Image_Validate = $IMAGES["B_A-Login_$img"];if($_POST['IMG_Valid'] != $Image_Validate) { $Error2 = "True"; $Error = "True";}$SQL_Login = "SELECT User_Name, `Password` FROM General_Stats WHERE User_Name = '".$_POST['User_Name']."'";$Login_Query = mysqli_query($DB_Server, $SQL_Login);if(empty($Login_Query)) { $Error3 = "True"; $Error = "True";}$DB_Login = mysqli_fetch_array($Login_Query);if(empty($DB_Login)) { $Error4 = "True"; $Error = "True";}if($Error != "True") { require("inc_files/B_A-Create_Cookies.inc"); header("Location: B_A-Base.php");}ob_end_clean();?>.....html output if necisary here[/code]thanks for any help Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 The only thing wrong with that code are the two lines.[code=php:0]$Error1 = "True";$Error = "True";[/code]should be....[code=php:0]$Error1 = True;$Error = True;[/code]Why don't you tell us what the problem is instead of trying to guess a solution. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 28, 2007 Author Share Posted January 28, 2007 the problem is that if i dont put on output buffering, i get the header error becauase variables and things have made output ( although i havent used echo or anytghing) amd if i do have it on, it just does the relkocation and header stuff .... even if there are errors...... can anyone help on this Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 You need to make sure you have no whitespace outside of any <?php tags within any of your included files aswell. This is also considered output. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 28, 2007 Author Share Posted January 28, 2007 ok, well there are definately no spaces or anything outside of the <?php tags ( at the begining ) so that is probably not the problem.... ill attach the file to this reply.... so you can see the full thing if you want[attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 28, 2007 Share Posted January 28, 2007 you also need to goto every page that is includded or attached to the page and cheek for white spaces not just the one you posted ok. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 28, 2007 Author Share Posted January 28, 2007 dont worry....i embeded the if's validating the login, in themselves... creating a sort of heirachy... this way the relocation can only happen if the rest of the stuf is incorect, ie the validation works. thanks anywayPC NERd Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 28, 2007 Author Share Posted January 28, 2007 soz guys, its not actually solved, i made a mistake.my code is as follows and always returns $Error1 as TRUE.... even if i lnow it isnt..... could this be something with the previous page becauase the data isnt being sent correctly.?[code]<?phpif(!empty($_POST['User_Name']) && empty($_POST['Password']) && empty($_POST['Valid'])) { $img_post_valid = "B_A-Login_".$_POST['IMG_Valid']; $Image_Validate = $IMAGES["B_A-Login_$img"]; if($_POST['IMG_Valid'] = $Image_Validate) { $SQL_Login = "SELECT User_Name, `Password` FROM General_Stats WHERE User_Name = '".$_POST['User_Name']."'"; $Login_Query = mysqli_query($DB_Server, $SQL_Login); if(!empty($Login_Query)) { $DB_Login = mysqli_fetch_array($Login_Query); if(!empty($DB_Login)) { require("inc_files/B_A-Create_Cookies.inc"); header("Location: B_A-Base.php"); } else { $Error = True; $Error4 = True; } } else { $Error = True; $Error3 = True; } } else { $Error = True; $Error2 = True; }}else {$Error = True;$Error1 = True;}[/code]thanks for all your help, the entire document is attached[attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 28, 2007 Author Share Posted January 28, 2007 does anyone have any ideas......i think on the attached file to my previous post.... that the if testing if the fields were empty.... all contitions had the !empty()......, not just the frirst.. so that wont make any differenecethanks for any help Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 28, 2007 Share Posted January 28, 2007 try using isset instead of empty. but that probably isnt the actual problem. first, i want to ask why you are using so much error variables.when i do some error checking, i usually have an array. then when i come across an error i do this:[code=php:0]$error[] = "Another error somewhere";[/code]Then when i get to the end of the page where i am going to login i do this:[code=php:0]if($error != ""){ //we have some errorsecho "Sorry but we encounted the following errors:<br>";$i = 1;foreach($errors as $er){echo $i.". ".$er."<br>"; //list out the errors$i++;}}else{ //no errors//log the user in} Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 29, 2007 Author Share Posted January 29, 2007 ok, i prefer to use the if's and individual variables just for reference...... but thats just my personal preference... but if its that thats cauaseing the error...then ill have to change it.i tried the isset ( ) ( but for the first if where its testing if the field is empty it wold have to be "if !isset($VAR_NAME)) and it doesnt workthanks for your help.... any more suggestions???thanks Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 29, 2007 Author Share Posted January 29, 2007 does anyone have any more ideas on this problem.... thanks Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 29, 2007 Author Share Posted January 29, 2007 ?????????? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 Project's way is a good one, IMO. That's how I do it. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 29, 2007 Author Share Posted January 29, 2007 well thats eccentially wat ive got..... but i use variables instead of arays....thats why im askin if there is nother error in my code Quote Link to comment Share on other sites More sharing options...
trq Posted January 29, 2007 Share Posted January 29, 2007 The header is error is the most common error you can get. It is caused by output being sent to the browser prior to a call to header(). All we can say is check your files for output.Bumping this thread every couple of hours / days is getting us nowhere. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 30, 2007 Author Share Posted January 30, 2007 yes i know about the header errors, but there is NO OUTPUT AT ALL.and im only bumping it every 4-6 hours. so .............. does anyone have anything to suggest Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 30, 2007 Share Posted January 30, 2007 alright. based off the code your returning $Error1 as true by checking that $_POST['User_Name'] ISN'T EMPTY and $_POST['Password'] IS EMPTY and $_POST['Valid'] IS EMPTY. So if you entered a password you would return $Error1 as true because its not empty.Are you sure they arnt all supossed to be !empty? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 30, 2007 Author Share Posted January 30, 2007 ok, thats not working.... changing to if(empty($VAR) || .............)thanks anyway........ Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 30, 2007 Share Posted January 30, 2007 try changing this[code=php:0]if(!empty($_POST['User_Name']) && empty($_POST['Password']) && empty($_POST['Valid'])) {[/code]to this:[code=php:0]if(!empty($_POST['User_Name']) && !empty($_POST['Password']) && !empty($_POST['Valid'])) {[/code]then it will check to see if they have values in them. the way you had it before didnt make sense. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 30, 2007 Author Share Posted January 30, 2007 still raises the $ERROR1 variable. and delivering the error message Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 30, 2007 Share Posted January 30, 2007 wat exactly is the error1 message. no data received or something? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 30, 2007 Author Share Posted January 30, 2007 well if the fields are empty (any one of them) , then it turns the error 1 variable to true, the then a later part on the script sayt if error1 is true, display message saying that you havent entered all the information., its all in the script posted above Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted January 30, 2007 Share Posted January 30, 2007 try this and see what happens:[code]<?php$username = $_POST['User_Name'];$password = $_POST['Password'];$valid = $_POST['valid'];echo "Username: {$username}<br>Password: {$password}<br>Valid: {$valid}<br><br>"; //echo out the values to see if they are being sent.if($username != "" || $password != "" || $valid != "") { $img_post_valid = "B_A-Login_".$_POST['IMG_Valid']; $Image_Validate = $IMAGES["B_A-Login_$img"]; if($_POST['IMG_Valid'] = $Image_Validate) { $SQL_Login = "SELECT User_Name, `Password` FROM General_Stats WHERE User_Name = '".$_POST['User_Name']."'"; $Login_Query = mysqli_query($DB_Server, $SQL_Login); if(!empty($Login_Query)) { $DB_Login = mysqli_fetch_array($Login_Query); if(!empty($DB_Login)) { require("inc_files/B_A-Create_Cookies.inc"); header("Location: B_A-Base.php"); } else { $Error = True; $Error4 = True; } } else { $Error = True; $Error3 = True; } } else { $Error = True; $Error2 = True; }}else {$Error = True;$Error1 = True;}?>[/code]if the values arn't being sent its something to do with the page sending them. maybe you have them named incorrectly. and is the valid variable like a captcha image or something? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 30, 2007 Author Share Posted January 30, 2007 ok, were getting somewhere....now tehe first time i did it.... the Valid array wasnt showing up(not ewchoing), and i discovered thathe name had its first char uppercase..... not lower.... but im still getting the error message ( i copied the rest of the code from my original.....ie, to display the errors.)i also tried changeing the || to a && but still nothing.thanks though, i think were getting somewhere Quote Link to comment 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.