U
U
unlik2018-04-17 02:10:00
PHP
unlik, 2018-04-17 02:10:00

switch case not working?

Why might this design not work?

<?php
switch ($_SERVER['REQUEST_URI']) {
  case "1.site.ru":
  $city = 'Москва';
  break;
  case "2.site.ru":
  $city = 'Воронеж';
  break;
}  
 ?>
<?php echo $city;?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-04-17
@Stalker_RED

Check what's really in $_SERVER['REQUEST_URI']
Or like this:

switch ($_SERVER['REQUEST_URI']) {
  case "1.site.ru":
    $city = 'Москва';
    break;
  case "2.site.ru":
    $city = 'Воронеж';
    break;
  deafult:
    $city = 'Неизвестный адрес ' . $_SERVER['REQUEST_URI'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question