GET参数不是空的,但我不能在PHP函数中使用它。

问题描述 投票:0回答:1

主文件的结构(index.php)

<?php
include('functions.inc.php');
include('page.php');
?>

在function.inc.php文件中,我定义了一个函数。

function getServiceAddonButtons($product)
        {     
                global $db; 
                $service = getServiceVar($product);
                $svaddon = $service['svdo_addon'];
                if (file_exists('content/addons/'.$svaddon.'/service_buttons/buttons.php') && addon_activated($svaddon) == 'YES') {
                    include('content/addons/'.$svaddon.'/service_buttons/buttons.php'); 
                }
            }

(这个文件中的其他函数已经定义好了,并且运行良好)

在page.php中,我使用了这个函数。

<div class='buttons'>
<?php getServiceAddonButtons($_GET['service_id']); ?>
</div>

当我在index.php上(page.php因为被收录而显示),我使用了url--------。https://example.com/index.php?manage_service=1&service_id=218

问题: 好像每次我在这个页面上的时候,函数的参数... getServiceAddonButtons($product) 是空的,但我用 $_GET['service_id']

有谁知道如何解决这个问题?

php parameters get include parameter-passing
1个回答
0
投票

你只需要在变量声明之后加上 "include"。

<?php
$variable = $_GET['service_id'];
include('functions.inc.php');
include('page.php');
?>

这个链接包含了所有关于你的问题的细节。PHP传递变量到include

© www.soinside.com 2019 - 2024. All rights reserved.