0

Structure of the main file (index.php)

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

In functions.inc.php file i definied a function:

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'); 
                }
            }

(Other functions on this file are already definied and working good)

In page.php i used this function:

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

When i'm on index.php (where page.php is shown because is included) I use url https://example.com/index.php?manage_service=1&service_id=218

THE PROBLEM: Seems like every time i'm on this page, the parameter of function getServiceAddonButtons($product) is null, but i used $_GET['service_id']

Anyone knows how to solve the problem?

Thos-Host
  • 67
  • 9
  • have you try to echo GET variable for see result? – Simone Rossaini May 04 '20 at 05:51
  • Yes, in page.php is returning the correct value (218) – Thos-Host May 04 '20 at 05:59
  • You said '_getServiceAddonButtons($product) is null_' because don't return include true? or $service variable in the function not work? try to use echo in all part of the function for test if variable is want you want. And are you sure exist $svaddon folder ? – Simone Rossaini May 04 '20 at 06:07
  • There is no problem with include, you see: there is a $product parameter in function, that's null even if i define it by using function($_GET['service_id']) – Thos-Host May 04 '20 at 06:13
  • if you echo `$_GET['service_id']` before function and show correctly (218) it's impossible is null, and the problem is in the function. – Simone Rossaini May 04 '20 at 06:15
  • *echo $_GET['service_id']* in file.php outputs 218 (correct value, but *echo $product* in function is returning nothing like the variable wasn't set. – Thos-Host May 04 '20 at 06:22
  • Try to see if $service - $svaddon containe correct data – Simone Rossaini May 04 '20 at 06:36

1 Answers1

0

You only need to make the "include" AFTER the variable declaration.

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

This link contains all the details regarding your problem: PHP pass variable to include

Apps Maven
  • 1,314
  • 1
  • 4
  • 17