• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[HELP] PHP transfering data back to index.php

Newbie Spellweaver
Joined
Apr 29, 2010
Messages
36
Reaction score
1
Hey. I have this kind of problem with login script (in login.php) and index.php. I want, when the person is logging in, to automatically get back to index.php (i have done that). AND to write a different comment of: "You have logged in successfully" or lets say for an example "User doesn't exist". Codes how i tried to do that (btw, my login is fully working):

from Login.php: #1
Code:
else
	$loginanswer3 = 'User doesn't exist!';
	echo "$loginanswer3";
	header( 'Location: Index.php' );
}

from Index.php: #2
this is to check if session has started to show different log in forms when person IS logged in and ISNT (works perfectly). Basically to recognise it...
Code:
         <?php session_start();
		 //report all errors except e-notice
		 error_reporting(E_ALL ^ E_NOTICE);
		 if ($_SESSION['username']) 
		 {  
		 ?>

Now, this is the one which doesnt work (doesnt show anything): #3
Code:
            <div id="trueorfalse">
            this text is visible
            <?php  
			if ($loginanswer3==TRUE)
			{
				echo "invisible, $loginanswer3";
			}
			
			?>
            </div>


I havent done the include: "login.php" anywhere, because when i do, my index.php becomes a mess. So i need code #3 to take info from login.php code #1 and show some info.... Anyway i think you understood what i am trying to do :D

Btw i am new to php, so dont judge me for noobishness of this question :D

I really need help with this... Thanks :)
 
Newbie Spellweaver
Joined
Oct 17, 2008
Messages
21
Reaction score
87
Where you change $loginanswer3 info to true?
 
Newbie Spellweaver
Joined
Apr 29, 2010
Messages
36
Reaction score
1
I only added
Code:
if ($loginanswer3==TRUE)
just before where "user doesnt exist" text should be displayed... Do i also need to change that info to true? And how to do that?

Edit: And maybe there is another way of displaying something like this? :/

Edit2: I changed code #1 code (in login.php) to:
Code:
else
	$loginanswer3 = TRUE;
	echo "$loginanswer3";
	header( 'Location: Index.php' );
}

and code #3 in index.php to:
Code:
            <?php  
			if ($loginanswer3 == TRUE)
			{
				$loginanswer3 = "user doesnt exist";
				echo "$loginanswer3";
			}
			else
			$loginanswer3 = "user exists";
				echo "$loginanswer3";
			?>
            </div>

but now it always says "user exists"... -_- even when i execute log-in...
 
Last edited:
Junior Spellweaver
Joined
Nov 26, 2008
Messages
196
Reaction score
62
Already looks like a mess. =P

You are using $loginanswer3 as a string variable, why are you even comparing it to a boolean?

Also, just a quick tip(s). If you are going to compare to a boolean, always use three comparison operators (===).

And when you want to each a variable, always string it.

PHP:
echo "invisible," . $loginanswer3;

PHP:
echo $loginanswer3;

Might actually find such mistakes may cause failed code execution. Seen it do it before.
 
Newbie Spellweaver
Joined
Apr 29, 2010
Messages
36
Reaction score
1
Edit: Problem solved by doing this:

Login.php
Code:
else
	header( 'Location: Index.php?loginans2=wpass' );
}
else
	header( 'Location: Index.php?loginans=wuser' );
}
else
	header( 'Location: Index.php?loginans3=upempty' );
	
?>

And Index.php:
Code:
<?php  
			$loginanswer = $_GET['loginans'];
			$loginanswer2 = $_GET['loginans2'];
			$loginanswer3 = $_GET['loginans3'];
			if ($loginanswer=="wuser")
			{
				$logans = "user doesnt exist!";
				echo $logans;
			}
			if ($loginanswer2=="wpass")
			{
			$logans2 = "wrong password";
			echo $logans2;
			}
			if ($loginanswer3=="upempty")
			{
			$logans3 = "must fill in all fields";
			echo $logans3;
			}
			else
			//do nothing
			?>

Even if it is a mess, it works :)

Thanks for those who helped me. :)
 
Last edited:
Junior Spellweaver
Joined
Nov 26, 2008
Messages
196
Reaction score
62
Edit: Problem solved by doing this:

Login.php
Code:
else
	header( 'Location: Index.php?loginans2=wpass' );
}
else
	header( 'Location: Index.php?loginans=wuser' );
}
else
	header( 'Location: Index.php?loginans3=upempty' );
	
?>

And Index.php:
Code:
<?php  
			$loginanswer = $_GET['loginans'];
			$loginanswer2 = $_GET['loginans2'];
			$loginanswer3 = $_GET['loginans3'];
			if ($loginanswer=="wuser")
			{
				$logans = "user doesnt exist!";
				echo $logans;
			}
			if ($loginanswer2=="wpass")
			{
			$logans2 = "wrong password";
			echo $logans2;
			}
			if ($loginanswer3=="upempty")
			{
			$logans3 = "must fill in all fields";
			echo $logans3;
			}
			else
			//do nothing
			?>

Even if it is a mess, it works :)

Thanks for those who helped me. :)

If you are not going to use that else at the bottom, just remove it. You are adding more code execution by not using something.
 
Back
Top