0

Hi i have a search box on all my web pages which shows 3 types of values i.e 1st Category, 2nd Sub-Category and 3rd Name. User selects a value in that box and redirected to URL "www.example.com/search.php?search='Any value'". After that Whatever user select in the search box, redirected to corresponding page.

For example.

If user chooses a category from select box then he/she is redirected to list.php.

header(Location: list.php/cat='$_GET[cat]')

And if user selects a Sub-Category then list1.php

header(Location: list1.php/subcat='$_GET[scat]')

And if user selects a name then page.php

header(Location: page.php/name='$_GET[name]')

I want user to redirect to corresponding page but keeping browser URL same as www.example.com/search.php?search='Value'

I tried hard to find it on Google but couldn't find a good example on that. Any help is appreciated. Thanks...

  • I think you need a one hidden input,which maintain choosen category depending upon your select you need to assign value to that input, then you can easily read the input in your list.php – Omi Mar 03 '17 at 08:39
  • create one page search.php and two get parameters. first search and second type(cat, subcat,name). it's not exactly what you want, but I can not think how you would want to do without type parameter – Martin Hrabal Mar 03 '17 at 08:41
  • @MartinHrabal Hi What i am doing right now is using a variable and storing get value in that variable. Then i run 3 sql queries to find which value is stored in that variable and in each sql query if it meets header works for that... – Ashish Garg Mar 03 '17 at 08:49
  • @Omi i am able to read input value well. Header are working well as i want. My problem is that my browser URL changing to HEADER location url that is i don't want to change. I want to keep www.example.com/search.php – Ashish Garg Mar 03 '17 at 08:51
  • @ashish you want to hide the url parameter right? – Omi Mar 03 '17 at 08:54
  • @Omi I want to hide header location URL in browser URL bar and show www.example.com/search.php?search='Value' instead. – Ashish Garg Mar 03 '17 at 08:56
  • Please have a look into this, this ll help you http://stackoverflow.com/questions/16388959/url-rewriting-with-php – Omi Mar 03 '17 at 09:00
  • @Omi Hi I have a point on that. These 3 pages(list,list1,page) already exists and showing results and i want to change URL of these pages only it is redirecting from search.php. If i use rewrite rules in .htaccess, If i am not wrong i think it will redirect all URLs on those pages too. Is it right or not ?? – Ashish Garg Mar 03 '17 at 09:08
  • Exactly e.g suppose you have selected cat then you ll redirect to list.php?search='Value' but if you would use .htaccess rewrite then it ll rewrite your list.php to search.php?search='Value, you can rewrite that using .htaccess – Omi Mar 03 '17 at 09:16
  • @Omi This is what i don't want. I am already using .htaccess. I just want to do it in case it is redirecting through search.php... – Ashish Garg Mar 03 '17 at 09:23
  • @AshishGarg You are on search.php and there you redirecting throught php header(location...) and you want to don't change url in browser in this case right? – Martin Hrabal Mar 03 '17 at 09:34
  • @MartinHrabal Absolutely sir.... – Ashish Garg Mar 03 '17 at 09:35
  • @AshishGarg Maybe iam wrong, but this is not possible this way. You can use ajax request? – Martin Hrabal Mar 03 '17 at 09:39
  • @AshishGarg or you can include like this here http://stackoverflow.com/questions/25093601/redirect-without-changing-the-browser-url – Martin Hrabal Mar 03 '17 at 09:41

0 Answers0