Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php变量不与include()一起使用_Php - Fatal编程技术网

php变量不与include()一起使用

php变量不与include()一起使用,php,Php,我试图将变量从userInfo.php传递到flips.php,但由于某些原因,变量无法传递。 当我做回显“hello”时在userInfo.php中,我确实在网站中看到“hello”,但当我看到时: if (isset($variable)) { echo "it is set!"; } else { echo "nope!"; } 然后它返回“不!”即使我在userInfo.php中设置了$variable userInfo.php: userInfo.php: 网站:www.csgo

我试图将变量从
userInfo.php
传递到
flips.php
,但由于某些原因,变量无法传递。 当我做
回显“hello”时
在userInfo.php中,我确实在网站中看到“hello”,但当我看到时:

if (isset($variable)) {
 echo "it is set!";
} else {
 echo "nope!";
}
然后它返回“不!”即使我在
userInfo.php
中设置了
$variable

userInfo.php:

userInfo.php:

网站:www.csgodonut.com(您必须登录steam才能看到
你好!不..
) flips.php位置:
csgodonut/application/views/gebruiker/home/flips.php
userInfo.php位置:
csgodonut/application/views/streamauth/userInfo.php

文件系统
/streamauth/userInfo.php
/gebruiker/home/flips.php
/gebruiker/home/home.php
userInfo.php
我只是通过更改控制器中的一个函数的$.get的url使其工作。

然后在该函数中,我加载了flips.php并发送$data(一个包含userInfo.php中所有变量的数组)。

不可能根据您提供的内容,确保显示完整代码这是所有内容,在我的代码中只有
$variable
被称为
$streamprofile
,除此之外,它是完全相同的no
我的意思是代码是相同的,
您是否在任何地方明确设置了
包含路径?您应该使用
get_include_path()
和/或使用
set_include_path()
检查include路径-也可以检查
flips.php
var_dump(get_include_files())中包含了哪些文件
~或尝试使用
require
查看可能出现的任何错误throw@Smokey嗯,有些东西不适合。。。如果你能给我们完整的代码,那将非常有帮助。否则我想我们中没有人能帮你。但是我可能错了:-)我只是通过将url从$.get更改为控制器中的一个函数,然后用$data加载flips.php(其中包含userInfo.php中的所有变量),不管怎样,谢谢您的帮助@斯莫奇,不客气。很高兴知道它现在起作用了。
<?php
$variable = "hello everyone!";
echo "hello!";
<?php
include ('userInfo.php');

if (isset($variable)) {
 echo "it is set!";
} else {
 echo "nope!";
}
include ('../csgodonut/application/views/steamauth/userInfo.php');
if (isset($steamprofile["personaname"])) {
  echo "yes!";
} else {
  echo "nope..";
}
$steamprofile['personaname'] = "Smokey";
echo "test";
<path-to-views-dir>/steamauth/userInfo.php
<path-to-views-dir>/gebruiker/home/flips.php
<path-to-views-dir>/gebruiker/home/home.php
<?php

$variable = "Hello everyone, I am the coolest variable!";

echo 'Hello from userInfo.php!<br/>';
<?php

include __DIR__ . '/../../steamauth/userInfo.php';

if (isset($variable)) {
    echo 'Helo from flips.php. The variable is set.<br/>';
} else {
    echo 'Helo from flips.php. The variable is NOT set.<br/>';
}
<?php

include __DIR__ . '/flips.php';

error_reporting(E_ALL);
ini_set('display_errors', 1);

if (isset($variable)) {
    echo 'Hello from home.php. The variable is set.<br/>';
} else {
    echo 'Hello from home.php. The variable is NOT set.<br/>';
}
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes" />
        <meta charset="UTF-8" />
        <!-- The above 3 meta tags must come first in the head -->

        <title>Demo</title>
        <script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function () {
                $('#testButton').click(function (event) {
                    alert('testButton clicked!');

                    $.ajax({
                        method: 'post',
                        dataType: 'html',
                        url: 'flips.php',
                        data: {},
                        success: function (response, textStatus, jqXHR) {
                            $('#results').html(response);
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            $('#results').html(textStatus + '<br />' + errorThrown);
                        },
                        cmplete: function (jqXHR, textStatus) {
                            //...
                        }
                    });

                });
            });
        </script>

        <style type="text/css">
            body {
                padding: 30px;
            }

            button {
                padding: 5px 10px;
                background-color: #8daf15;
                color: #fff;
                border: none;
            }
        </style>
    </head>
    <body>

        <button type="button" id="testButton" name="testButton">
            Fetch some data
        </button>

        <br/><br/>

        <div id="results">
            Here comes the response data from the ajax request...
        </div>

    </body>
</html>