S
S
snake_jan2017-12-17 16:05:07
PHP
snake_jan, 2017-12-17 16:05:07

How to set a password only for the main page of a PHP site?

Hello. There is a self-written engine in php.
Its main page is Index.php
The task is to set a password for access to Index.php, leaving all directories and subdirectories of the site untouched. That is, the password should be only on the main page, is it real? And if so, how?
update:
I'm sorry, I don't know if it's appropriate.... but here's my code....
Here's the Index.php source:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

include_once('./lib/Index.php');
include_once ('./lib/Wiev.php');

if(!empty($_GET['show_yourself']))
{
  $wiev = new Wiev();
  $wiev->generateContent();
  $wiev->writeContent();
}

$index = new Index();

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Инструмент для CPA V2.0</title>
  <link rel="stylesheet" type="text/css" href="lib/css/index.css">
  <script type="text/javascript" src="lib/js/jquery-1.10.2.js"></script>
  <script type="text/javascript" src="lib/js/index.js"></script>
</head>
<body>

<?php foreach ($index->scanAll() as $unit) { ?>

  <div class="unit_container">
    <div class="unit_head">
      <?php print($unit['path'])?> <a class="unit_content_toggle" href="#">показать / скрыть</a>
    </div>
    <div class="unit_content">
      <table>
        <tr>
          <td>static</td>
          <td><?php print($index->makeStatus($unit['static_status']))?></td>
        </tr>
        <tr>
          <td>content</td>
          <td><?php print($index->makeStatus($unit['content_status']))?></td>
        </tr>
        <tr>
          <td>config</td>
          <td><?php print($index->makeStatus($unit['config_status']))?></td>
        </tr>

        <tr>
          <td>настройка<br/>просмотра</td>
          <td>
            <div class="unit_config">
              <table  class="unit_config_table">
                <thead>
                <tr>
                  <th>Параметр</th>
                  <th>Значение</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                  <td>
                  Ссылка на лендинг<br> <strong>*обязательно с http://</strong>
                  </td>
                  <td>
                    <input type="text" class="parameter" name="url">
                  </td>
                </tr>
                </tbody>
              </table><br>
              <a class="show_your_self" href="#" target="_blank">ПОСМОТРЕТЬ ★</a>
            </div>
            <script>
              $('.unit_config:last').data('config', <?php print($unit['config'] ? $unit['config'] : '[]')?>);
              $('.show_your_self:last').data('path', '<?php print($unit['path'] ? str_replace('/','_',$unit['path']) : '')?>');
            </script>
          </td>
        </tr>
      </table>
    </div>
  </div>

<?php } ?>

<script>

  $(function(){

    function checkConditions(evt, container = false){

      if(!container && evt){
        container = $(evt.target).closest('.unit_config')
      }

      var params = {};
      $(container).find('.parameter').each(function(key,element){
        if($(element).attr('type') == 'checkbox'){
          if($(element).is(':checked')){
            params[$(element).attr('name')] = $(element).val();
          }
        }else{
          params[$(element).attr('name')] = $(element).val();
        }
      });
      $(container).find('.parameter').each(function(key,element) {
        var currShowCondition = $(element).data('showCondition');
        if (currShowCondition) {
          if (new Function('return ' + currShowCondition).call(params)) {
            $(element).closest('tr').show();
          } else {
            $(element).closest('tr').hide();
          }
        }
      });
    }

    $('.unit_config').each(function(key, container){
      var l_params = $(container).data('config');

      $.each(l_params, function(key, val) {
        new_element = '';
        if (val.type == 'checkbox') {
          var new_element = $('<input>');
          new_element.attr({
            type: 'checkbox',
            class: 'parameter',
            name: val.name,
            value: val.value
          });
          if (val.value == val.def) {
            new_element.attr('checked', 'checked');
          }
          if(val.showCondition){
            new_element.data('showCondition', val.showCondition);
          }
        }
        if (val.type == 'number') {
          var new_element = $('<input>');
          new_element.attr({
            type: 'number',
            class: 'parameter',
            name: val.name,
            value: val.value,
            min: val.min,
            max: val.max,
            step: val.step,
            value: val.def
          });
          if(val.showCondition){
            new_element.data('showCondition', val.showCondition);
          }
        }
        if (val.type == 'select') {
          var new_element = $('<select></select>');
          new_element.attr({
            class: 'parameter',
            name: val.name
          });
          if(val.multiple){
            new_element.attr('multiple',1);
          }
          $.each(val.values, function(key1, val1) {
            var option = $('<option></option>');
            option.text(val1.value);
            option.attr('value', val1.value);
            if(val1.value == val.def){
              option.attr('selected','selected');
            }
            option.appendTo(new_element);
          });
          if(val.showCondition){
            new_element.data('showCondition', val.showCondition);
          }
        }
        if (new_element != '') {
          new_element.change(checkConditions);
          var tr = $('<tr></tr>');
          tr.append($('<td></td>').text(val.label));
          tr.append($('<td></td>').append(new_element));
          $(container).find('.unit_config_table').find('tbody').append(tr);
        }
      });

      checkConditions({}, container);

      $(container).find('.show_your_self').click(function(evt){
        var params = {
          show_yourself: 1,
          path: $(evt.target).data('path')
        };
        $(container).find('.parameter').each(function(key,element){
          if($(element).attr('type') == 'checkbox'){
            if($(element).is(':checked')){
              params[$(element).attr('name')] = $(element).val();
            }else{
              params[$(element).attr('name')] = 'off';
            }
          }else{
            params[$(element).attr('name')] = $(element).val();
          }
        });
        window.open('/?' + $.param(params),'_blank');
        return false;
      });

    });
  });

</script>

</body><code lang="php">

</code>
</html>

I would be very grateful for any help, in the past a coder, in php knowledge is very minimal :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2017-12-17
@Maksclub

then this service for what???
If you don't know, then why write something at all.

The service needs to help those who are looking for help...
How can you help those who do not help themselves?!
For me, a normal script is a standalone script without authorization ... or it is an authorization script without reference to index.php
Here's how you can help people give you an answer:
Everything is real, you can make server registration general, for example
but the check for whether it is registered is displayed only on index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question