包含 - 与直接链接不同的结果

发布于 2024-10-21 06:59:46 字数 1307 浏览 3 评论 0原文

我有以下 php 代码:

<html>
  <body>
    <?php
    $_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too
    include('scores.php');
    ?>
  </body>
</html>

使用此代码,我尝试包含此 http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML< /a> 直接链接有效,但您可以在此处看到包含的结果: http://apps.facebook .com/krajecr/pokus.php - 错误:警告:fclose():提供的参数不是 /3w/webz.cz/p/programming/facebook/scores.php 中的有效流资源第 9 行

你能帮我解决这个问题吗?

Scores.php 可以在这里找到 http://www.scores.php flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php ()

这里是前 10 行:

<?php

    $winscore = (int)$winscore;

    // Create a Blank File if it doesn't already exist
    if (!file_exists($filename))
    {
        $file=fopen($filename, "w");
        fclose ($file);
    }

I have the following php code:

<html>
  <body>
    <?php
    $_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too
    include('scores.php');
    ?>
  </body>
</html>

With this code I'm trying to include this http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML
The direct link works, but you can see the result from the inclusion here: http://apps.facebook.com/krajecr/pokus.php - error: Warning: fclose(): supplied argument is not a valid stream resource in /3w/webz.cz/p/programming/facebook/scores.php on line 9

Can you please help me solve this?

scores.php can be found here http://www.flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php ()

here are the first 10 lines:

<?php

    $winscore = (int)$winscore;

    // Create a Blank File if it doesn't already exist
    if (!file_exists($filename))
    {
        $file=fopen($filename, "w");
        fclose ($file);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-10-28 06:59:46

该错误表明您正在尝试对非流资源的内容执行 fclose 操作。

假设您从 fopen 获取了 $file,这里唯一的情况是 fopen 失败,因此 $file 不是流资源,而是FALSE。例如,如果您的网络服务器运行的用户没有创建该文件的权限,则可能会失败。

为您的函数调用添加错误检查。

我无法解释为什么当您让 PHP 通过网络执行包含请求时情况会有所不同。

编辑

$_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too

应该是

$_GET = Array(
    'filename'  => 'scores/score.sco',
    'scoresize' => '10',
    'action'    => 'VIEW',
    'viewtype'  => 'HTML'
);

绝对在任何地方退出尝试使用HTTP查询字符串语法;世界不是这样运作的!

我还注意到“scores.php”似乎从未定义$filename是什么。难怪文件创建失败:您从未给它提供有效的文件名来创建!检查 fopen 的返回值(正如您始终应该做的那样)会发现此错误。

您可能想写 $_GET['filename']

The error says that you're trying to do fclose on something that's not a stream resource.

Assuming you got $file from fopen, the only scenario here is that the fopen failed so that $file is not a stream resource, but FALSE. It might fail if, for example, the user that your webserver is running as does not have permissions to create the file.

Add error checking to your function calls.

I can't explain why this would be different when you have PHP do the inclusion request over the web.

Edit

$_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too

should be

$_GET = Array(
    'filename'  => 'scores/score.sco',
    'scoresize' => '10',
    'action'    => 'VIEW',
    'viewtype'  => 'HTML'
);

Quit trying to use HTTP querystring syntax absolutely everywhere; that's not how the world works!

I also notice that "scores.php" never seems to define what $filename is. No wonder the file creation is failing: you never give it a valid filename to create! Checking the return value of fopen — as you always should — would have revealed this error.

You probably meant to write $_GET['filename'].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文