supergrame Posted March 19, 2009 Share Posted March 19, 2009 im not to good at explaining what i want but ill give it a go, i have a login form called loginhtml.php and it posts to loginphp.php now if the user is in the DB it will go to members area if not it will output a wrong user name, the thing is it echo that on the loginphp.php, its just blank with wrong username and pass witch is what is meant to happen but i want that to redirect back to the login form and print it out there. i hope that makes scene, i could assign it to a global variable but im sure there is another way. i was thinking of redirecting back with header: loginhtml.php but it wont have a clue about that error, I am a newbie at this but slowly getting better. phpfreaks is mean place to learn and get help:D well i hope that makes scene to you all if not ill try to reexplain it thank you Quote Link to comment Share on other sites More sharing options...
Kalland Posted March 19, 2009 Share Posted March 19, 2009 To redirect the user back you can use javascript: document.location = 'loginhtml.php'; Quote Link to comment Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 yea i no i can redirect back but the issue is the error generated via loginphp.php wont get posted to the loginhtml.php page witch is what i want. maybe im just not thinking outside of the squre this php stuff really messes up my brain i guess in time it will be easier to follow and a lot less of a headache, but so far PHP is awesome im getting so addicted Quote Link to comment Share on other sites More sharing options...
Kalland Posted March 19, 2009 Share Posted March 19, 2009 You could try to set a value for your input fields like so: value="<?php echo $_POST['username']; ?>" And redirect using: document.history(-1); Quote Link to comment Share on other sites More sharing options...
Kalland Posted March 19, 2009 Share Posted March 19, 2009 Sorry, that will not help you with getting the errors to that page... Quote Link to comment Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 yea but thanks tho, You would think there would just be an easy way, maybe i should just have the php at the top of my html but then again that's not really the right way to set up your file structure, well for me anyway. Quote Link to comment Share on other sites More sharing options...
Kalland Posted March 19, 2009 Share Posted March 19, 2009 One way could be to put the errors in the link when you redirect: header("Location: loginhtml.php?erorrs=$errrors"); Maybe not the best way, but may work. Quote Link to comment Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 yea not really the way i was looking for but at least it will do for now untill i get a little better maybe ill stumble accross a better way, :-\ Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 19, 2009 Share Posted March 19, 2009 I recommend you do not use javascript for this at all. You should use a redirect when the user input is correct otherwise it should redirect to the form it self <?php //you should catch if the login was correct somehow if the login was correct then redirect if(validlogin){ header("Location: your_secured_page.php"); exit(); } ?> <form action="thisformname.php" method="post"> <input type="text" name="username" value="<?php echo(isset($_POST['username']))?$_POST['username']:"";?>"/> <input type="password" name="password" /> </form> Quote Link to comment Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 i have the redirect if the login is successful its just if the user entered wrong details, i need it to echo an error message above the login form on the previous page. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 19, 2009 Share Posted March 19, 2009 Have you searched the forum for "login script"(or anything similar). I am pretty sure this topic has been discussed many times. The information thats allready available might be of good use to you. Quote Link to comment Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 nothing really in the search i have a felling most people put the php with the html form i did have it like that originally but i wanted to separate the php and html as much as i could.. :-\ Quote Link to comment Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 ok here the best way i have come up with, instead of trying to call a variable i just used the include function and put all necessary files in my skeleton index.php 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.