包含 - 与直接链接不同的结果 [英] inclusion - different result than with direct link

查看:27
本文介绍了包含 - 与直接链接不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 php 代码:

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>

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

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 可以在这里找到 http://www.flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php ()

scores.php can be found here http://www.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);
    }

推荐答案

该错误表明您正在尝试对非流资源执行 fclose.

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

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

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.

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

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

编辑

$_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 查询字符串语法;世界不是这样运作的!

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

我还注意到scores.php"似乎从来没有定义过 $filename 是什么.难怪文件创建失败:你从来没有给它一个有效的文件名来创建!检查 fopen 的返回值 —就像你一直应该的那样—会发现这个错误.

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.

您可能打算编写 $_GET['filename'].

这篇关于包含 - 与直接链接不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆