azraelGG Posted October 31, 2012 Share Posted October 31, 2012 hi currently i created login form and its working but i want replace my echo messages be below form not above how can i replace it (is it possible without repeating code) here is the code <?php //username and password check - start session or display wrong username and password if (isset($_REQUEST['login'])){ $korisnickoIme=$_REQUEST['korisnickoIme']; $lozinka=$_REQUEST['lozinka']; if ($korisnickoIme=='admin' && sha1($lozinka)=='7110eda4d09e062aa5e4a390b0a572ac0d2c0220') { $_SESSION['logiran']='da'; $_SESSION['korisnickoIme']=$korisnickoIme; } else{ echo "Molimo unesite ispravne podatke."; } } //display login form - if someone clicked logout button or not logged in if ( (isset($_REQUEST['logout']))||(!isset($_SESSION['logiran'])) ) { echo '<!--start of login form sidebar--> <form id="login" action="index.php" method="post"> <label>Korisničko ime:</label> <input type="text" name="korisnickoIme" id="korisnickoIme" /> <label>Korisnička šifra:</label> <input type="password" name="lozinka" id="lozinka" /> <input type="submit" value="Login" name="login" /> </form>'; if(isset($_REQUEST['logout'])){ session_destroy(); echo "Uspješno ste se odjavili."; } } //if user is logged in display logut form elseif (isset($_SESSION['logiran'])) { echo "Logirani ste pod imenom ".$_SESSION['korisnickoIme']; echo'<!--start form for logout --> <form id="logout" action="index.php" method="post"> <input type="submit" value="Logout" name="logout" /> </form> '; } ?> i want that part of code else echo "Molimo unesite ispravne podatke" below form this other echo shows at bottom because that code is below form. any way to reposition that echo or how do i do it Quote Link to comment https://forums.phpfreaks.com/topic/270115-code-working-but-i-want-position-echo-elsewhere/ Share on other sites More sharing options...
Christian F. Posted October 31, 2012 Share Posted October 31, 2012 I hope that you just posted that hash as a placeholder for this forum, and that your actual password isn't "1234". Anyway, for your question: Save the string in a variable, instead of echoing it out at the top. Then just echo the variable wherever you want it to be. Quote Link to comment https://forums.phpfreaks.com/topic/270115-code-working-but-i-want-position-echo-elsewhere/#findComment-1389031 Share on other sites More sharing options...
azraelGG Posted October 31, 2012 Author Share Posted October 31, 2012 no this is just example without database nice idea, thanks Quote Link to comment https://forums.phpfreaks.com/topic/270115-code-working-but-i-want-position-echo-elsewhere/#findComment-1389041 Share on other sites More sharing options...
Christian F. Posted October 31, 2012 Share Posted October 31, 2012 Good to hear, and you're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/270115-code-working-but-i-want-position-echo-elsewhere/#findComment-1389043 Share on other sites More sharing options...
azraelGG Posted October 31, 2012 Author Share Posted October 31, 2012 (edited) i add this code and it works now as i wanted - did you had another idea? behind login form ofc if(isset($_REQUEST['login'])){ echo isset($krivoIme); } Edited October 31, 2012 by azraelGG Quote Link to comment https://forums.phpfreaks.com/topic/270115-code-working-but-i-want-position-echo-elsewhere/#findComment-1389044 Share on other sites More sharing options...
azraelGG Posted October 31, 2012 Author Share Posted October 31, 2012 wrong this code is correct if(isset($_REQUEST['login'])){ if(isset($krivoIme)) echo $krivoIme; } Quote Link to comment https://forums.phpfreaks.com/topic/270115-code-working-but-i-want-position-echo-elsewhere/#findComment-1389045 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.