Hello! I would like to hear your opinion.

There is an implementation of loading the necessary page, suppose that this code is located at the link http://test.ru/city.php:

<?php switch ($_REQUEST['CITY']) { case moscow: // Если город Москва, то подключаем страницу moscow.php $url = "http://test.ru/moscow.php"; break; default: // Если все остальные города, то подключаем страницу anyone.php $url = "http://test.ru/anyone.php"; } header('Location: ' . $url); exit; ?> 

After the loaded page, for example, I want to change the city, I have a special block on the page, with which I select the city I need in the drop-down list and click on it. This block sticks to the URL of the page where I am at the moment, the parameter passed, say, http://test.ru/city.php?CITY = moscow . After that, I downloaded the page http://test.ru/moscow.php , since the parameter passed was moscow . Then I want to change the city again, choose another city from the list, BUT I am already on the page http://test.ru/moscow.php , and it turns out that the URL will look like this http://test.ru/ moscow.php? CITY = anyone , in fact, I will see the same page http://test.ru/moscow.php , but I need to paste the passed parameter again to the URL of the page http://test.ru/city.php . I can not rigidly link the link in the block to the page http://test.ru/city.php , you know, because the city change block attaches the transmitted parameter to the URL of the page I am currently located at. Option to register switch in each page does not give a ride. Please help me figure it out!

  • When you click on the desired city, redirect through the header to test.ru/city.php with the city parameter. and he will redirect to the desired page with the desired url. - Barton
  • @archi_sova, that is, when choosing a region, do you need a form to appear that corresponds to this choice? If yes, then you do not need to go to some other page, but simply output one or another form ... toli from the base, toli from the file, etc. PS And I can not give you an exact answer, because I do not know how the script works for you, and indeed how the structure of the site is arranged. - Deonis
  • And the redirect fails because the GLOBAL_CITY parameter flies to the page online_form.php (if I am on it), and the handler is in the file online_form_connect.php (my switch is described in it), i.e. it turns out that GLOBAL_CITY = (conditionally Ufa) I pass to the page online_form.php because I stand on it then my block sticks to the URL online_form.php? GLOBAL_CITY = 1525, but I don’t have a handler on the page online_form.php and I cannot do it there because I will do something I will constantly loop on the same page. - Artyomich
  • @Deonis, unfortunately I cannot add a RewriteRule — I can't either, I can rather, but I can't do that. And so the principle agrees - Yes! this is a decision. But you can not: ( - Artyomich
  • Hmm ... As they say in Odessa: "You make my heartbeat" =). That is impossible, it is impossible. I do not even know what to say to you. - Deonis

2 answers 2

Connect on the necessary pages a handler that will receive a GET request with the CITY parameter and redirect to the necessary page or pull the necessary data from the database to the page.

  • It always exists, suppose that by default I turn to the test.ru/city.php page already with the parameter CITY = moscow, i.e. The page serves for initial determination of the region, i.e. if in the block a different region was previously selected, then I’ll go to the test.ru/city.php page with the anyone parameter, respectively, if moscow was previously selected, it means that I’m going to the page with the Moscow parameter, and the city.php page will redirect me to page. It is necessary that from the pages of moscow.php and anyone.php I could go respectively to the desired page when choosing the desired city in the block - Artyomich
  • It turns out that when you go to the online_form_connect.php page there is a redirection of the selected region, we assume MOSCOW, I go to the page, we allow online_form.php, and then on the same page online_form.php I select the UFA region, I should see the online_form_ufa.php page, but I after all transferred the GLOBAL_CITY parameter to the page online_form.php and not to the page online_form_connect.php where the redirect is actually registered, therefore the page online_form.php is displayed to me again. - Artyomich
  • I can not connect because all GET variables are destroyed somewhere before by the code and I can get GLOBAL_CITY only from $ _REQUEST ['REGIONALBANK_SM_CITY']), or I don’t understand the mot, it’s not destroyed, but I can’t display it exactly ex, therefore and decided that destroyed. - Artyomich
  • Now I looked and you still use mod_rewrite. So you need to search either "above by code", or as suggested by @DDD (answer below) - add the rule to .htaccess. - Deonis
  • Aaaaaa everything turned out :) Doper, as you said, just added a counter: <? Php // echo "<p style = 'color: red;'> The file was loaded - <strong> online_form_ufa.php </ strong> </ p> "; + $ RSC = $ _REQUEST ['REGIONALBANK_SM_CITY']; echo "We came from page: <b>". $ _SERVER ['HTTP_REFERER']. "</ B> <br>"; echo "The variable <b> REGIONALBANK_SM_CITY </ b> exists and is equal to:". $ RSC; if (isset ($ _ REQUEST ['REGIONALBANK_SM_CITY']) && $ _REQUEST ['REGIONALBANK_SM_CITY'] == 1054) {$ url = " alfa.rbrbank.ru/clients/private/crediting/consumer/… "; header ('Location:'. $ url); }?> - Artyomich

In .htaccess add

 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ city.php?url=$1 [L,QSA] 

All requests will go to the city.php file and, depending on the request, load the necessary information.

  • does not work: ( - Artyomich
  • That's all the same, an interesting solution with RewriteRule, I google it at the expense of this, I still did not make the line correctly, you can tell how the alfa.rbrbank.ru/clients/private/crediting/consumer/… page will look like for this page - Artyomich