Suppose I have an install.php file, and install.php has $ 5 _REQUEST

I.e:

$_REQUEST['step'] 5 штук. step=1; step=2; step=3; step=4; step=5 

How can I make the page source code (install.php) displayed, as well as if I’ve scored in the install.php address bar? Step = 1, then the content changes. The same as organizing the function of limiting step. Ie, with step = 1, it is impossible to go to step = 3, as well as restrictions, that stepov is only 5 and they cannot be negative.

    2 answers 2

    Maybe something like this?

     <?php if(isset($_REQUEST['step'])){ switch($_REQUEST['step']){ case '1': $_SESSION['step_'] = 1; //Шаг 1 break; case '2': if($_SESSION['step_'] == 1){ $_SESSION['step_'] = 12; //Шаг 2 }else{ exit(); } break; case '3': if($_SESSION['step_'] == 12){ $_SESSION['step_'] = 123; //Шаг 3 }else{ exit(); } break; case '4': if($_SESSION['step_'] == 123){ $_SESSION['step_'] = 1234; //Шаг 4 }else{ exit(); } break; case '5': if($_SESSION['step_'] == 12345){ $_SESSION['step_'] = 12345; //Шаг 5 }else{ exit(); } break; } }else{ //Error } ?> 
    • You did not specify the most important thing. So that at your step you have your content. echo will only add above the main one. - Dmitry Alekseevich
    • instead of "// Step n" you specify your content - Elime
    • Nightmare. I am not a php guru, but are there really no other solutions, with less r **** code? I don’t even spare the time and try to implement it. - AlexDenisov
    • @ 1101_debian, I didn’t strain too much (I couldn’t strain myself: D) Well, come on, implement, check, your “miracle” code. - Elime pm
    • It is a poor attempt to implement an under-control controller ... Actually, what is the question and answer, what did you want? **** I do not claim that this is a normal code, but for such a task - roll =) - Zowie
     <? $views = array('home.html', 'profile.html', 'about.html'); include $views[$_REQUEST['step']]; echo 'Came from => '.$_SERVER['HTTP_REFERER']; ?> 

    The way to display different content depending on the parameters. The array contains the file names (views) in which the necessary information is stored for a specific step. The penultimate line displays the URL from which the user came, in a particular view you can check it. But this is not the best option, I am sure that there are more adequate means, but I do not know them, because far from php.

    • @ 1101_debian - something like this is done. But it is at least like programming. what is higher is more like a meta description =) - Zowie
    • Have you read the assignment carefully? - Elime
    • Elime, yes, and what's wrong? - AlexDenisov pm
    • @ 1101_debian, well, it is written in the assignment that it is impossible to go from the first step to the third step immediately / any other. That is, you can only go in order from first to fifth. You can walk around without any restrictions. - Elime
    • one
      @Elime - let's say inattentively he read the task, nevertheless - it would be possible to create separate scripts for each step and connect them if such a file exists, if not - shine the legendary 404. Suppose there were 200 such steps, what would you do? Would you write 200 branches of a switch? How sad it is, but: Code reuse ~ = 0 && flexibility ~ = 0 === true About the transition in order - just add one more condition, i.e. if (file_exists ($ stepvalue. '.php') && $ _SESSION ['step'] == ($ _GET ['step'] - 1)) - Zowie