Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to GET parameters functioning in include_once

Tags:

php

when i call include once without any GET parameters it works but with setting GET parameters on trackinglogs.php nothing happens please suggest me what do to..

my php code is: firstfile.php

include_once('trackinglogs.php?todo=setcookie');
?>

my second file is trackinglogs.php

<?php
    $action=$_GET['todo'];
    switch($action)
{
    case "setcookie":
    echo "hi";die();
    break;

    default:
    echo "error"; die();
    break;
}

?>

thanks for you precious time

like image 263
spiderman Avatar asked Mar 28 '26 01:03

spiderman


1 Answers

You cannot pass parameters when including like that, include does not make an HTTP request.

The most minimal solution, although I do not recommend it, is to simply set the parameters yourself so that trackinglogs.php finds them:

$_GET['todo'] = 'setcookie';
include_once('trackinglogs.php');

A much better solution would be to put the code that tracks logs inside a function, and call that providing this operating parameters at the same time. So you 'd have something like:

<?php    
function track($action) {
    switch($action) {    
        case "setcookie":    
        echo "hi";die();    
        break;    

        default:    
        echo "error"; die();    
        break;    
}    

And you would do:

include_once('trackinglogs.php');
track('setcookie');
like image 161
Jon Avatar answered Mar 29 '26 21:03

Jon