Cipri Posted October 29, 2012 Share Posted October 29, 2012 Hi there, im new to this forum and preaty mutch new to php.. so i hope you guys can help me out here I wana make a simple page on my website, with a imput form (text area) where client can imput a text, a password for example, and based on that password, they will be redirected to their specific client page. Like here... u go to www.mysite.com/client, here u enter the imput password then will redirect you to www.mysite.com/client/clientname Can this be done with php? Thanks a lot and hope i explained right. Have a nice day and realy hope someone can help me here. Cipri Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/ Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 (edited) <?php $blah = htmlentities($_POST['whatever']); if($blah == "something") { header("Location: client/clientname"); } ?> Edited October 29, 2012 by ExtremeGaming Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/#findComment-1388522 Share on other sites More sharing options...
Cipri Posted October 29, 2012 Author Share Posted October 29, 2012 thanks a lot ExtremeGaming, this is the .php file that i have to add in the form? as the action file? sry im realy new to it and trying to understand. I made a client page with this in it <div align="center"> <form action="redirect.php" method="get" name="input">Username: <input type="text" name="user" /><input type="submit" value="Trimite" /></form> </div> the code that you gave my, i need to put it inside the redirect.php file if im right. after that this should work? and can i add another "if" for another client, and maybe a "else" if the imput is wrong? realy appreciate your help, thanks a lot. Cipri Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/#findComment-1388525 Share on other sites More sharing options...
Christian F. Posted October 29, 2012 Share Posted October 29, 2012 (edited) ExtremeGaming: I would not use htmlentities () (nor htmlspecialchars ()) there, seeing as you're not sending the variable's content to the browser. Instead you've made it quite impossible to match the "password", if it contains a character that would be encoded by the function. Cipri: The "action" file can be the same file as the one that's displaying the form, if you set the action of the form to be empty the browser will post the data back to the current URL. Just remember to parse all PHP at the top of the page, before any (and all) HTML code is sent to the browser. There are lots of examples on how to make a proper (and secure) form with HTML and PHP, and a search of the forum will bring you lots and lots of examples. I recommend looking at the posts made by the people with badges, or some of my own, for some proper examples. The "Header errors" thread, which is stickied at the top of this section, is also a very good read. Edited October 29, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/#findComment-1388548 Share on other sites More sharing options...
Cipri Posted October 30, 2012 Author Share Posted October 30, 2012 Thanks a lot Christian F. for your time and your reply, other problem thats on my mind atm, is that i forgot to mention i'm using a wordpress based website, and im creating a page inside wordpress where i wana put this script. Is there a probem with wp interpretaiting the php code inside the page? thanks a lot for your guide, i will take a look over them. Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/#findComment-1388635 Share on other sites More sharing options...
Christian F. Posted October 30, 2012 Share Posted October 30, 2012 It shouldn't be a problem, no, but I can't give you any guarantees. Don't know how Wordpress handles its output, and thus it may have sent something to the browser before running your code. If it has, your header calls will fail. You'll find out soon enough though, once you test it. You're welcome, btw. Glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/#findComment-1388670 Share on other sites More sharing options...
MDCode Posted October 30, 2012 Share Posted October 30, 2012 ExtremeGaming: I would not use htmlentities () (nor htmlspecialchars ()) there, seeing as you're not sending the variable's content to the browser. Instead you've made it quite impossible to match the "password", if it contains a character that would be encoded by the function. The point of htmlentities was if they were to display anything that was input. But now that you mention it..my bad Quote Link to comment https://forums.phpfreaks.com/topic/270047-redirect-based-on-form-imput/#findComment-1388776 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.