Can you use $ _GET variables when including a file in PHP? Is this even possible with an AJAX call?

I have a PHP file that handles sending confirmation letters. I also have a calendar that I use AJAX to perform various updates. When AJAX calls the update file, it updates the database with new information, and I want to send confirmation emails.

So, from within the php file that calls AJAX, I decided I should include("email-sender.php?stage=confirm2a&job={$slot->job_id}, which calls the php email, with $ _GET variables that tell which emails to send and to whom.

But for some reason, I can't get include to work when you use ?key=value$ _GET pairs attached to a string. PHP.net tells me that you can use the $ _GET variables in include, but when I set up a simple test, it does not work.

There is one link on my test page that, when clicked, calls an ajax call to the page along with data containing one variable "farm", which is equal to the value "animal". Like this:

$("a.testlink").click(function() {
    var mydata = "farm=animal";
    $.ajax({
        url: "ajaxPHP.php",
        data: mydata,
        success: function(rt) {
            alert(rt);
        }
});

So ajaxPHP.php says:

if($_GET['farm']) {
    $var = $_GET['farm'];
    echo $var;
}

At this point, a success warning shows an "animal" when the link is clicked. It is right.

But if I change ajaxPHP.php to this:

if($_GET['farm']) {
    $var = $_GET['farm'];
    include("ajaxInclude.php?farm={$var}");
}

And you have a file called ajaxInclude.php that states:

if($_GET['farm']) {
    $var = $_GET['farm'];
    echo $var;
}

Then, when I click the link, I get a blank warning. Thus, include does not work with the query string added to the end.

?

, :

$stage = "confirm2a";
include("email-sender.php");
$stage = "confirm2b";
include("email-sender.php");

email-sender.php, , , :

if($stage == "confirm2a") { 
   email Person 1 etc...
}
if($stage == "confirm2b") {
    email Person 2 etc...
}

script, Person 1 . , ...

+3
3

script, include:

$var = "foo";
include("script.php");

- script.php -

echo $var; // 'foo'

-, . , , script.php, .

+9

, , :

1)


if($_GET['farm']) {
    $var = $_GET['farm'];
    $farm = $var;
    include("ajaxInclude.php");
}

ajaxInclude.php:


if($farm) {
    $var = $farm;
    echo $var;
}

2)


if($_GET['farm']) {
    $var = $_GET['farm'];
    header("Location: ajaxInclude.php?farm={$var}");
}
0

$_GET - , php script,

0

Source: https://habr.com/ru/post/1730547/


All Articles