这是一个代码:
<?php
require_once('./includes/connection.inc.php');
session_start();
// create database connection
$connread = dbConnect('read', 'pdo');
$connwrite = dbConnect('write', 'pdo');
$komentari = 'SELECT * FROM komentariodobreni ORDER by komentarodobren_id DESC';
$kontakt = 'SELECT poruka_id, ime, prezime, email, predmet, ordinacija, poruka, DATE_FORMAT(datum, "%H:%i:%s %d. %b. %Y")
AS datum FROM kontakt ORDER by poruka_id DESC';
if (isset($_POST['slanje'])) {
$potvrdiquery = "SELECT * FROM kontrola WHERE adminname='" . $_POST["adminname"] . "' and adminpassword = '". $_POST["adminpassword"]."'";
$stmt = $connwrite->prepare($potvrdiquery )
;
// bind the parameters and execute the statement
// execute and get number of affected rows
$stmt->execute();
$OK = $stmt->rowCount();
foreach ($connread->query($potvrdiquery) as $row) {
$_SESSION['adminid'] = $row['adminid'];
$_SESSION["adminname"] = $row["adminname"];
$_SESSION["adminpassword"] = $row["adminpassword"];
}
header('Location: index.php');
}
?>
它在我的本地计算机上运行良好,但是当我将其上传到Ipage或其他服务器时,它没有注册会话变量。
最佳答案
尝试像这样重新排列session_start():
<?php
session_start();
require_once('./includes/connection.inc.php');
...
并尝试一下。 connectoin.inc.php中可能发生了某些错误(错误或输出),导致session_start()无法正常工作。
为了帮助调试问题,请添加如下错误输出:
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once('./includes/connection.inc.php');
...
关于php - session 在localhost上有效,但在服务器(Ipage等)上无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21301262/