1

I had pages that contain duplicate codes. I wrote this line of code and used the query string to avoid repeating codes in every page:

$m=$_GET['m'];
$p=$_GET['p'];
include_once "$m/$p.php";

$m is the directory that contains page $p. page $p is the content that must place in the non-fixed area of the main page. the main page is something like this:

<body>

    <section id="container" class="">
        <!--header start-->
        <header class="header white-bg">

        </header>

        <aside>
            <div id="sidebar" class="nav-collapse ">
                <!-- sidebar menu start-->
                <ul class="sidebar-menu">
                    <li class="active">
                        <a class="" href="siturl?m=index&p=dashboard">
                            <i class="icon-dashboard"></i>
                            <span>dashboard</span>
                        </a>
                    </li>
                </ul>
            </div>
        </aside>

        <!--main content start-->
        <section id="main-content">
            <section class="wrapper">
                <?
                    $m=$_GET['m'];
                    $p=$_GET['p'];
                    include_once "$m/$p.php";
                ?>
            </section>
            <!--main content end-->
        </section>

        <script src="js/script1.js"></script>
        <script src="js/script2.js"></script>
        <script src="js/script3.js"></script>
 </body>

after I click on the links on the sidebar who defined like this:

<a class="" href="siturl?m=index&p=dashboard">
         <i class="icon-dashboard"></i>
         <span>dashboard</span>
   </a>

all scripts will be deleted despite they are out of the section that i placed content.

SLePort
  • 14,405
  • 3
  • 28
  • 39
mohammadreza khalifeh
  • 1,262
  • 2
  • 14
  • 29
  • 1
    which `script` remove ? – Bhargav Chudasama Jul 04 '18 at 04:47
  • 2
    Yikes ! you better find approach than this `include_once "$m/$p.php";` –  Jul 04 '18 at 04:47
  • @Dr.Strange all of them – mohammadreza khalifeh Jul 04 '18 at 04:48
  • 1
    i didn't understand your question ? – Bhargav Chudasama Jul 04 '18 at 04:49
  • 1
    Either [get PHP to display errors](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) or check your error logs and try again. More than likely the file you're including is producing some sort of error that is being logged, but you're not seeing it. – Mike Jul 04 '18 at 04:51
  • 1
    Also, make sure none of the included pages are doing `exit` or `die` as this will prevent further execution. – Mike Jul 04 '18 at 04:52
  • @Dr.Strange im adding the content in a section with the wrapper class...and scripts deleted is out of that section – mohammadreza khalifeh Jul 04 '18 at 04:53
  • 1
    This is absolutely dangerous! What do you think would happen if I passed a value like `../../somenonpublicfolder` for the parameter `m` …? And appending `.php` at the end might not be as safe as you think either. You really need to go read up on how to implement something like this _properly_. – CBroe Jul 04 '18 at 07:41

0 Answers0