Jump to content

looking for something similar to ob_start()


PC Nerd

Recommended Posts

hi guys.  im creating a login script..... basically going like:

if ( errors, create relevent variable warning.)
else(cookies and re;locate user)


BUT


becauase 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]<?php

ob_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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]<?php
if(!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]
Link to comment
Share on other sites

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 differenece

thanks for any help
Link to comment
Share on other sites

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 errors
echo "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
}
Link to comment
Share on other sites

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 work

thanks for your help.... any more suggestions???

thanks
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.