bander Posted January 17, 2007 Share Posted January 17, 2007 Expert?Have problems populating $_POST when RewriteRule is invoked by URL's param. When no param is given in URL you can post the form and see the vars that are posted with print_r($_POST), with param nothing is posted!See the action? Take a look at he following URLs:http://test.inmo-exclusive.com/ //OK!http://test.inmo-exclusive.com/eng //NOT OK!Here is the code:.HTACCESS-----RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^([a-z]{3})$ /?lang=$1 [L]RewriteRule ^([a-z]{3})/$ /?lang=$1 [L]INDEX.PHP-----<?phpecho "Your post:";print_r($_POST);?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><form action="" method="post"> <input name="name" type="text"> <input name="submit" type="submit" id="submit" value="Submit"></form></body></html> Any help would be appreciated!! Quote Link to comment Share on other sites More sharing options...
Stray_Bullet Posted January 18, 2007 Share Posted January 18, 2007 Um neither one of those links are okay... This is what I see...[URL=http://img171.imageshack.us/my.php?image=huhic0.jpg][IMG]http://img171.imageshack.us/img171/9761/huhic0.th.jpg[/img][/URL]First off this is wrong...[code]form action=""[/code]Your sending the post info nowhere...Here... I created a little form for you here is the code...[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?phpif($_POST['op'] != "send") { # display the form # $display_block = "<h1>Type your name & submit!</h1> <hr> <p> </p> <form method=\"post\" action=\"$_SERVER[PHP_SELF]\"> <input type=\"text\" name=\"name\"> <input type=\"hidden\" name=\"op\" value=\"send\"> <p><input type=\"submit\" name=\"submit\" value=\"Post It\"></p> </form>"; }else if($_POST['op'] == "send") { # check for required fields # if($_POST['name'] == "") { header("Location: index.php"); exit; } $display_block = "<h1>Your name is...</h1> <hr> <p> </p> <b>$_POST[name]</b>";}echo "$display_block\n"?></body></html>[/code]Just a helpful hint... It is not a good idea to allow anyone to post anything without some kind of checks being made... This only includes one check to see if the name is blank... More should be added if this is to be open to unknown people... In my opinion... Hope this helps! ;D Quote Link to comment Share on other sites More sharing options...
bander Posted January 18, 2007 Author Share Posted January 18, 2007 Hi thnx,I have posted this prob in several forums, but no replies on my comment what so ever, accept here, thnx for it!Leaving the "action-tag" empty, tells the form, to post the vars to it self. I never set the "action-tag" to post to a particular page and always works just fine. But I believe it's better policy to tell forms action explicit where to post his vars. I might consider that this host I am working on, not support RewriteRules the way I am working. At my own dedicaed server I have no problems with it. Other thing is, $_POST is a superglobal, therefore it should not matter where the vars are posted right?Seeing your code example, try not to code your php inline but only make includes and var echo/print in HTML. This benefits you as developer helping organize your code (seperate logic from presentation code) better, and designers are less confrontend with logic code to make adaptions in HTML.This is just a case problem description, I am fully aware about filtering data that comes from$_GET and $_POST concerning cross site scripting, injections and so on..., thnx anyway.ps. Strange that the URLs both are going wrong. Problem should be, without param (http://test.inmo-exclusive.com/) you can see your post vars in de array printed above uppon clicking the button. With param (http://test.inmo-exclusive.com/eng), Note the "/eng" it looses the post and you will see nothing in the array. 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.