相关疑难解决方法(0)

SET NAMES命令失败,访问被拒绝

我试图在这个例子e之后插入一个重音到mysql数据库.使用这个:

mysql_query("SET NAMES 'utf8'");
Run Code Online (Sandbox Code Playgroud)

抛出:

警告:mysql_query()[function.mysql-query]:拒绝访问用户'ODBC'@'localhost'

它没有连接到数据库:

DEFINE ('DB_USER', 'user');
DEFINE ('DB_PASSWORD', 'pword');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'test1');
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
Run Code Online (Sandbox Code Playgroud)

php mysql unicode utf-8

5
推荐指数
2
解决办法
3万
查看次数

PHP:如何检查用户是否已登录,否则重定向到登录页面

我是PHP新手,我正在努力解决以下问题:

我有一个页面,我想在他们看到网站内容之前检查某人是否是注册用户.所以我的想法是在我的头文件(在所有单个页面上引用require_once("includes/header.php");)我可以检查并将它们重定向到登录页面(login.php),如果他们还没有登录.

所以这是我在标题中的所有内容:

<!DOCTYPE html>
<html>
    <head>
        <?php 
            define("someUnguessableVariable", "anotherUnguessableVariable");
            session_start();
            if(!(isset($_SESSION['login']) && $_SESSION['login'] != '')){
                header ("Location: login.php");
            }

            include "system/config.php";

            $pageURL = basename($_SERVER["REQUEST_URI"]);
            $pageName = pathinfo(parse_url($pageURL, PHP_URL_PATH), PATHINFO_FILENAME); 

            $selectedLang = $_GET["lang"];
                if(!isset($selectedLang)){
                    $selectedLang = "de";
                }
            $langURL = "?lang=" . $selectedLang;

            $conn = new mysqli($dbServer, $dbUser, $dbPass, $dbName);
            $conn->set_charset("utf8");
            if($conn->connect_error){
                die("Connection failed: " . $conn->connect_error);
            } 
            // fetch main translations
            $location = "%main%";
            $stmt = $conn->prepare("SELECT tID, " . $selectedLang . " FROM TranslationsMain …
Run Code Online (Sandbox Code Playgroud)

php session redirect login session-variables

5
推荐指数
1
解决办法
3万
查看次数

为什么include()不允许工作setcookie?

我需要在我的页面中设置cookie,但它会返回

Warning: Cannot modify header information - headers already sent by (output started at /home1/bsam/public_html/24kadr/index.php:1) in /home1/bsam/public_html/24kadr/basic_login.php  on line 35
Run Code Online (Sandbox Code Playgroud)

在第1行我有

include 'basic_login.php'; 
Run Code Online (Sandbox Code Playgroud)

但即使我删除include,ir也会在session_start或mysql_connect上返回相同的警告.所以我认为这些函数在调用时都使用标题,但我该怎么办?至少我需要连接到数据库,就在它之后我需要使用setcookie().那我该怎么办?谢谢

更新index.php的第一行

<?include 'basic_login.php';include 'settings.php';?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
...........
Run Code Online (Sandbox Code Playgroud)

在basic_login.php中它启动

<?
session_start();
include 'connect.php';
ini_set("session.bug_compat_42",1);
ini_set("session.bug_compat_warn",0);
Run Code Online (Sandbox Code Playgroud)

..........................................

setcookie("cookname", $_SESSION['username'], time()+60*60*24*30, "/");
setcookie("cookpass", $_SESSION['password'], time()+60*60*24*30, "/");
Run Code Online (Sandbox Code Playgroud)

php

4
推荐指数
1
解决办法
891
查看次数

php标头已经发送错误

可能重复:
PHP已发送的标头

我有一个php文件,其中包含以下代码:

<?php header("Location: somepage.php"); ?>
Run Code Online (Sandbox Code Playgroud)

在php打开或关闭标签之前或之后绝对没有空格我得到了

Warning: Cannot modify header information - headers already sent by (output started at C:\ ... \test.php:1
Run Code Online (Sandbox Code Playgroud)

通常当我收到此错误时,1是问题的行号,但在这种情况下,第一行没有任何额外的空格.我只在页面上有这个代码,我不包括任何其他文件.

我在windows xp上使用xampp.任何想法正在发生什么或我如何能够找出导致问题的真正原因.

谢谢

php header

4
推荐指数
1
解决办法
6151
查看次数

session_start()错误

我对session_start()有一些问题;

我知道在session_start()之前不应输出任何内容; 声明

但我无法在我的剧本中找到问题

index.php文件:

<?php session_start();
include('functions.php');
if(!is_logged_in(session_id())){
    include('form.php');
}else{
?>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)

但我总是跟着错误:

警告:session_start()[function.session-start]:无法发送会话cookie - 已经在C:\ xampp\htdocs\fertige_scan中发送的输出(输出从C:\ xampp\htdocs\fertige_scan\index.php:1开始)第1行的\ index.php

我希望你能帮帮我 :)

php session

4
推荐指数
2
解决办法
1184
查看次数

Codeigniter:标头已发送错误

我有一个CI应用程序,具有auth控制器和switchuser功能.基本上它只需要从URI获取ID,从ID获取一些用户数据,分配一些会话数据然后加载视图.

function switch_user(){
    if(!$this->auth_lib->is_admin()){
       $this->session->set_flashdata('status', 'You need to be an administrator to access this page.');
       redirect('auth/login');
    }

    if($id = $this->uri->segment(3)):
            $this->load->model('auth_model', 'auth');
            $username = $this->auth->get_username($id)->account_name;
            $this->session->set_userdata(array('at_id' => $id, 'username' => $username));
            $this->session->set_flashdata('status','User switched.');
    endif;
    $this->load->model('clients_model', 'clients');
    $data['users'] = $this->clients->get_at_clients();
    $this->load->view('auth/switch', $data);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cp\application\controllers\auth.php:130)
Run Code Online (Sandbox Code Playgroud)

第130行是$ username = $ this-> auth-> get_username($ id) - > account_name;

这是模型功能:

function get_username($at_id){
     $portal = $this->load->database('warehouse', TRUE);
     $portal->select('account_name');
     $portal->where('account_id', $at_id);
     $portal->from('wh_account');

     $query …
Run Code Online (Sandbox Code Playgroud)

php codeigniter http-headers

4
推荐指数
1
解决办法
2万
查看次数

警告:session_start()[function.session-start]:无法发送会话cookie - 已经发送的标头

可能重复:
PHP中的"警告:已发送标头"

大家好我在PHP登录表单上显示错误,当我将其上传到我的服务器时.它在我的localhost上工作得很好,但是当我将它上传到服务器时,它给了我这个错误:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 45

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 45

Warning: Cannot modify header information - headers already sent by (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 49
Run Code Online (Sandbox Code Playgroud)

这是我的PHP代码:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="http://localhost/Shopping_biblioteka/css/style.css">
        <title>Title</title>
    </head>
    <body …
Run Code Online (Sandbox Code Playgroud)

php session

4
推荐指数
1
解决办法
2万
查看次数

wp_redirect()函数在WP管理员中不起作用

我将尝试在wordpress admin中使用以下代码进行重定向.

if(isset($_POST['submit'])) 
    {
wp_redirect('admin.php?page=job-creation');
}
Run Code Online (Sandbox Code Playgroud)

我也尝试wp_redirect('admin.php?page=job-creation');而不是

wp_safe_redirect('admin.php?page=job-creation'); 
Run Code Online (Sandbox Code Playgroud)

header('location: admin.php?page=job-creation');
Run Code Online (Sandbox Code Playgroud)

所有代码在localhost中都正常工作.但它不能在线工作(www.example.com).

帮帮我.

php wordpress plugins redirect wordpress-plugin

4
推荐指数
1
解决办法
6900
查看次数

WP_redirect 不起作用(标头已在pluggable.php 中发送)

我想在模板文件中使用此代码:

if ( wp_is_mobile() ) {
wp_redirect( "/shop-mobile", $status );
}
Run Code Online (Sandbox Code Playgroud)

但它说:标头已由 /filewithcode 在 .../wp_includes/pluggable.php 第 1196 行发送

我尝试清除可插入文档中的空格。这里还有什么问题?谢谢

php wordpress redirect

4
推荐指数
1
解决办法
8522
查看次数

输出发送后调用 header()

根据 PHP 文档:

header()必须在发送任何实际输出之前调用,无论是通过普通的 HTML 标记、文件中的空行还是来自 PHP。使用 include 或 require 函数或其他文件访问函数读取代码,并且在调用 header() 之前输出空格或空行,这是一个非常常见的错误。使用单个 PHP/HTML 文件时存在同样的问题。

但是当我尝试文档报告的示例时(稍作改动):

<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header('X-Header: http://www.example.com/');
exit;
?>
Run Code Online (Sandbox Code Playgroud)

一切正常,没有出现错误,我顺利地<html>在输出和X-Header标题中找到了我的标签。

我使用的是 PHP 7.1.9,所以文档所说的仍然正确吗?

php

4
推荐指数
1
解决办法
784
查看次数