There is a code that does not work. The class works correctly, the problem is only in the function header ();

<?php include '../../classes/Band.php'; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ session_start(); $error = false; if(isset($_POST['name']) && !empty($_POST['submit'])){ $name = $_POST['name']; $band = new Band($name); if(isset($_FILES['band_img']['name'])){ $img = $_FILES['band_img']; $_SESSION['error'] = $band->addBand($img); if (!empty($_SESSION['error'])){ $error = true; } }else{ $_SESSION['error'] = 'Фаил не выбран'; $error = true; } }else{ $_SESSION['error'] = 'Введите название альбома'; $error = true; } if ($error === true){ header("Location: ../admin_templates/admin_template.php?s=0"); }else{ header("Location: ../admin_templates/admin_template.php?s=1"); } ?> 

Question:

How in this case to implement transitions to other pages (templates) depending on the value of the flag? Thanks in advance for your help.

  • you get rid of .. for starters, you see, and earn. - teran
  • Ask one question, please, referring only to the code for each in each. - D-side
  • Unfortunately, this error displays: "The localhost site has redirected too many times." - Vadim Vova
  • @ VadimVova this can happen if you have redirects in a circle. You can open the developer’s toolbar in the browser and look at the requests performed on the Network tab. - teran
  • @teran I think it is so, but how to solve this issue?) - Vadim Vova

1 answer 1

 if ($error === true){ header("Location: http://www.test.com/admin_templates/admin_template.php?s=0"); exit; // die(); - или можно так }else{ header("Location: http://www.test.com/admin_templates/admin_template.php?s=1"); exit; } 
  • The same mistake. Nothing has changed. - Vadim Vova
  • session_start to the very beginning - recomendated
  • try to remove the GET parameter, if the redirect happens normally, then just drive s = 0 to $ _SESSION ['s'] = 0. And in admin_template.php type in session_start (); - recomendated
  • and else with parentheses can be removed, it is not needed here - recomendated
  • All the same. Do you have such redirects with flags working normally? - Vadim Vova