duancai7002 2017-03-02 03:56
浏览 21
已采纳

是否可以检测页面是否包含PHP?

My site is basically 5 "pages" and about 30 "helper pages" that are called by php includes, sometimes 1 or 2 "helper pages" per "page", sometimes 10+ per "page."

Because these are includes I have certain variables and my mysql connection code in the "page" and the helper pages relies on these variables. For example, here is my "edit.php" page:

<form method="POST" enctype="text/plain" action="<?php echo $actual_link; ?>">

<div class="one-hundred"><?php include("include/pages/vehicle.php"); ?></div>

<div class="fifty"><?php include("include/pages/vehicle_valuations.php"); ?></div>
<div class="fifty"><?php include("include/pages/vehicle_features.php"); ?></div>

<div class="thirty-three">
    <?php 
        include("include/pages/purchased_info.php"); 
        include("include/pages/vehicle_Titles.php"); 
    ?>
</div>

<div class="thirty-three"><?php include("include/helper_content/warranty_lookup.php"); ?></div>
<div class="thirty-three"><?php include("include/pages/vehicle_advertising.php"); ?></div>

<div id="buttons">
    <input type="submit" id="Submit" value="Submit">
</div>

What I'm wondering is if I direct my browser directly to www.____.com/include/pages/vehicle.php the page fails, because of the missing mysql connection script and missing variables. Is there a way to detect if someone is accessing the page directly, or through an iframe or ajax or include?

  • 写回答

3条回答 默认 最新

  • drll42469 2017-03-02 04:07
    关注

    You could look for a $_GET parameter inside the php file that was "included."

    For example,

    include(".../file.php?included=true");
    

    Then, inside file.php...

    <?php
    
    if isset($_GET['included']) {
    
    //page was "included!"
    
    }
    

    But when the user visits the page via http://... there's no $_GET parameter added to the URL string, hence the page wasn't included.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探