【问题标题】:How to debug PHP script not executing?如何调试未执行的 PHP 脚本?
【发布时间】:2013-09-12 05:58:27
【问题描述】:

我正在这里http://beta.fray.it/invite 上创建一个wordpress 页面,点击Twitter 图标时,我在列表元素上设置了这个onclick 属性

onclick="window.location.href = '<?php echo get_template_directory_uri(); ?>/components/invite/twitter/redirect.php';">

这会将我带到应该将用户重定向到 Twitter 进行身份验证的 php 文件。我在我用于测试的另一台服务器上得到了这个工作,但不是在这里。发生的情况是我看到了来自主页http://beta.fray.it 的内容,但没有重定向。这是什么原因?

【问题讨论】:

  • 是否有任何错误输出到页面或服务器上的错误日志?
  • redirect.php 里面是什么?因为它向我显示了一个页面。也许您没有将该文件上传到服务器。
  • 我在页面上看不到错误输出。检查了我在服务器上放置文件的文件夹,没有看到错误日志,我还能在哪里检查这些日志?
  • redirect.php 的内容:getRequestToken(OAUTH_CALLBACK); $oauth_token = $request_token['oauth_token']; $_SESSION['oauth_token'] = $oauth_token; $oauth_token_secret = $request_token['oauth_token_secret']; $_SESSION['oauth_token_secret'] = $oauth_token_secret; $url = $connection->getAuthorizeURL($oauth_token); header('位置:'.$url); ?>
  • 我在上面的位置上传了 2 个随机文件并尝试通过浏览器访问它们。这个beta.fray.it/wp-content/themes/fray/components/invite/twitter/… 正确输出了文本文件的内容。但是,这个不是beta.fray.it/wp-content/themes/fray/components/invite/twitter/…,好像我无法执行任何 php 文件

标签: javascript php wordpress redirect


【解决方案1】:

在 wp-config.php 中启用 WP_DEBUG 和 WP_DEBUG_LOG 后(WP_DEBUG 默认禁用,因为 WP_DEBUG 设置为 false)。

当出现错误、警告、通知或日志调用时,会在 /wp-content/ 目录中生成 debug.log。

您还可以利用包装函数来集中您的日志调用

if(!function_exists('_log')){
  function _log( $message ) {
    if( WP_DEBUG === true ){
      if( is_array( $message ) || is_object( $message ) ){
        error_log( print_r( $message, true ) );
      } else {
        error_log( $message );
      }
    }
  }
}

你可以阅读更多关于 here

也请查看手抄本: http://codex.wordpress.org/Debugging_in_WordPress

【讨论】:

  • 发现我的问题是由于 htaccess。我更改了文件的位置,现在它可以工作了。
【解决方案2】:

尝试更改您的链接href

 onclick='window.location.href =' + "<?php echo get_template_directory_uri(); ?>" + '/components/invite/twitter/redirect.php';

【讨论】:

    猜你喜欢
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 2011-02-09
    • 1970-01-01
    相关资源
    最近更新 更多