Jump to content

Recommended Posts

I have a form get like this

 

<form action="<?php echo $_SERVER['REQUEST_URI']."&";  ?>" method="get" name="search">

 

that form is for example on www.mywebsite.com/search.php?cat=1001

 

if I click submit button, I'm expecting this

 

www.mywebsite.com/search.php?cat=1001&search=textbox_anything

 

 

But it is always redirecting me to

 

www.mywebsite.com/search.php?search=textbox_anything

 

It is removing the cat=1001

 

 

Is there any alternative?

Link to comment
https://forums.phpfreaks.com/topic/266367-_get-and-request_uri-complict/
Share on other sites

If you set method=get then the query string in the action URL will be overwritten with whatever the form data is.

 

It looks like all you're expecting is the category ID? Put that in a hidden field.

</pre>
<form action="search.php" method="get" name="search">
" /><

Uh, I posted something potentially very bad. Try again:

<form action="search.php" method="get" name="search">
<input type="hidden" name="cat" value="<?php echo (int)$_GET["cat"]; ?>" />

XSS

 

Just a question, so (int) is necessary to increase security on every numeric data that will be pass on the url? are htmlentities and urlencode also suitable for this?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.