doudou8081 2014-01-26 07:41
浏览 89

解析从html到php的url参数?

I have a website with a large amount of dynamic content. I have a main template page that then loads the content into it. I have SSI running fine (including to php files) but I cannot get the php files to see the url parameters from the html page. I would rather not convert all my html files to php files if I can help it.

The following code gets to the php file ok (ie displays hello world.) but what do I put for the ???? to get the topic passed from the html url to the included php file?

Ive tried $_GET which works if I call the page directly (ie place getDynamicContent.php?topic=X in the browser) but not when called through #include.

.

for a url: mainPage.shtml?topic=X

.

in mainPage.shtml

//this includes fine - no problems
    <!--#include "commonHeaderStuff.html"-->

//this includes but does not parse variable
    <!--#include "getDynamicContent.php"-->

.

in getDynamicContent.php

//get topic variable
    $topic=????

//return content based on $topic
    echo "hello world";
    if($topic=="X"){echo "You passes an X"}
    else {echo "You passes a Y";}
  • 写回答

1条回答 默认 最新

  • dsi36131 2014-01-26 07:47
    关注

    You need to use $_GET

    if(isset($_GET['topic'])){
        $topic = $_GET['topic'];
        echo "hello world";
        if($topic == "X"){
            echo "You passes an X";
        }else{
            echo "You passes a Y";
        }
    }else{
        #no topic
    }
    

    Heres an attempt of mine by searching for a way to pass variables to a included from Get url and parameters with SSI

    <!-- set default value for SSI variable "topic" -->    
    <!--#set var="topic" value="" -->
    
    <!-- get "topic" value from URL --> 
    <!--#if expr="$QUERY_STRING = /topic=([a-zA-Z0-9]+)/" -->
    <!--#set var="topic" value="?topic=$1" -->
    <!--#endif -->
    
    <!--#include virtual="getDynamicContent.php${topic}"-->
    

    I tested this just now and it works also I had to add virtual= to have it work but you might need to change it to file=. you can change <!--#set var="topic" value="" --> to whatever default value you want eg: value="?topic=X"

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM