会话php5.5 mysqli不存储信息

时间:2015-11-02 07:37:22

标签: php session mysqli

我在uni上创建了一个网站http://www.mandyevansartist.com并且已经让它在ipage上工作 - 因为移动到1和1它不起作用。会话信息适用于第一页(中途下载

$_SESSION['name']=$name; 
$_SESSION['thispic']=$thispic;

已创建并适用于弹出模式 - 但信息将在下一页丢失

    <?php
session_start();
include 'header.php';
$id = isset($_GET['id']) ? $_GET['id'] : "";
$con =   mysqli_connect("*","*","*","*");
$db = mysqli_select_db("images", $con);

function GetCartId()
{

    if(isset($_COOKIE["cartId"]))
    {
        return $_COOKIE["cartId"];
    }
    else
    {
        setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
        return session_id();
    }
}
$id = $_GET["id"];
$strSQL = "SELECT * FROM images WHERE image= '$id'";
$rs = mysqli_query($con,$strSQL);

while($row = mysqli_fetch_array($rs)) {

    $name =   $row['image_name'];
    echo '<h1 style="font-size:2em;">';
    echo $name;
    echo'</h1>';
    echo '<div id = "galpic">';
    $thispic = $row['image'];
    echo '<div id = "pic">';        
    echo '<br /> <img src="'.$thispic.'" style = "max-width:100%;"/> ';
    echo '</div>';      
    $description =   $row['image_description'];
    echo ' <a href="#" class="big-link" data-reveal-id="about" data-animation="fade"><h3>about</h3></a>';
    echo ' <a href="#" class="big-link" data-reveal-id="card" data-animation="fade"><h3>card</h3></a>';
    echo '</div>';      
}
$_SESSION['name']=$name; 
$_SESSION['thispic']=$thispic;
echo '<div id="about" class="reveal-modal">';
echo '<br /> <img src="'.$thispic.'" /> ';
echo '<h1>';
echo $description;
echo '</h1>';
echo '</div>';
echo '<div id="card" class="reveal-modal">';
echo '<br /> <img src="'.$thispic.'" /> ';
echo '<img src="images/cards.png" /> ';
echo '<h1>a card of -'.$name.'</h1>';
echo '<p>click this button and we will hand make you this card. Using   spray glue on recycled card and a crystal archive photograph. Individually   wrapped with a c5 envelope. </p>';
echo '<h1>$7 each</h1><br />';

echo '<form action = "cart.php" method = "post">';
echo '<input type="image" src = "images/sendtocart.png" >';
echo '</form>';
echo '<p> you can remove it from the cart later if you like</p>';
echo '</div>';

$catagory = mysqli_query($con,"SELECT catagory FROM images WHERE image=   '$id'");
echo '<p>';
while   ($row = mysqli_fetch_array($catagory))  {
    $yay= $row[catagory];
}
$answer   = mysqli_query($con,"SELECT image FROM images where catagory =   '$yay'");
echo '<div id = "list">';
echo '<hr></hr>';
echo '<p>other pictures in this catagory</p>';
echo '<ul>';        
while   ($row   =   mysqli_fetch_array($answer))    {
    $pic = $row['image'];       
    $link ="<a href = 'image.php?id=".$row['image']."'>". ' <img   src="'.$pic.'" style ="height:45px;"/> '. "</a>";  
    echo '<li>' .$link.'</li>';     
}
echo '</ul>';
echo '</div>';

$answer = mysqli_query($con,"SELECT image FROM images where HEAD =   'true'");
echo '<div id = "list">';
echo '<hr></hr>';
echo '<p>choose another catagory</p>';
echo '<ul>';        
while   ($row=mysqli_fetch_array($answer))  {
    $pic = $row[image];     
    $link ="<a href = 'catagory.php?id=".$row[image]."'>".' <img     src="'.$pic.'" style ="height:60px;"/>'."</a>";   
    echo '<li>'.$link.'</li>';    
}
echo '</ul>';
echo '</div>';
include 'footer.php';
?>
<a class="close-reveal-modal"></a>

到达下一页时会话信息消失

     <?php
session_start();
$_SESSION['name']=$name;
$_SESSION['thispic']=$thispic;
$con = mysqli_connect("*","*","*","*");
function GetCartId()
{
    if(isset($_COOKIE["cartId"]))
    {
        return $_COOKIE["cartId"];
    }
    else
    {
        setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
        return session_id();
    }
}
mysqli_query($con,"insert into cart(product,name,image,price,cookieId)  values('card','$name','$thispic',7,'".GetCartId()."')");
header("Location:image.php?id=$thispic");
?>

1 个答案:

答案 0 :(得分:0)

问题解决了 - 这是1and1主持人没有&#39; superglobals&#39;打开 - 所以我把这个代码添加到我的相关页面的顶部(就在session_start().....

下面
// Emulate register_globals on
 if (!ini_get('register_globals')) { 
     $superglobals = array($_SERVER, $_ENV,
     $_FILES, $_COOKIE, $_POST, $_GET);
 if (isset($_SESSION)) { 
     array_unshift($superglobals, $_SESSION); 
} 
foreach ($superglobals as $superglobal) { 
    extract($superglobal, EXTR_SKIP); 
 }
  }