...

View Full Version : $_Session not storing on first attemp



aagarathi
11-25-2011, 09:53 AM
Please help me on my coding im having problem with the session which only storing the session on second on the first it just not storing any session


<?php



//session_id($sid);



session_start();

ob_start();

if(!isset($_SESSION['ddc']['cartqty'])) $_SESSION['ddc']['cartqty'] = 0;

if(!isset($_SESSION['ddc']['price'])) $_SESSION['ddc']['price'] = 0.00;



include('includes/config.php');

include('includes/functions.php');

include('includes/header.php');

$msearch = $_GET['search'];

$_SESSION['msr']="$msearch";

?>



<?php
session_start();
if ($_SESSION['sort'] == ""){
$_SESSION['sort']="ORDER BY name";
$_SESSION['sortby']="ASC";
$_SESSION['view']="12";
}

echo $_SESSION['msr']
?>



<div class="clear"></div>

<div id="menulisting">
<div style="margin-bottom : 10px">
<a href="mobilesms.php">
<img id="mobile" src="assets/images/mobilesms.jpg" style="border: 0px none;"></a>
</div>

<?php include('includes/menu.php'); ?>
<p>
</p>
<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FDonkeez%2F147416101995311&amp;width=180&amp;colorsc heme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;height=250" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:180px; height:250px;" allowTransparency="true"></iframe>
</div>



<div id="productlisting" style="border: 0px none;">



<div id="intcategories">

<div id="categoryname"><h>Product Search</h></div>
<div id="new">New product
</div>

<div id="newproduct">
<marquee behavior="scroll" scrolldelay="100" direction="left" onmouseover="this.stop();" onmouseout="this.start();" style="height: 50px;"> <div id="newproduct1">
<?php


$sql3 = "SELECT * FROM ddcart_products ORDER BY id DESC LIMIT 0,8";
$result3 = mysql_query($sql3);
while($data3 = mysql_fetch_assoc($result3)) {
?>
<img src="<?php echo 'productimages/'.$data3['stock'], '.jpg'; ?>">
<?php } ?></div>
</marquee></div>

<div class="clear" style="height: 1px;"></div>

</div>



<div id="newborder">
<div id="intcategories2">



<div id="subcats" style="height: 40px;"><form method="get" action="search.php">
<input type="text" style="height: 26px; width: 139px; padding-bottom: 0px; padding-top: 0px; margin-bottom: 5px; margin-top: 5px;" class="box" value="" name="search">
<input type="submit" value="Search" class="button">


</form></div>

<div class="clear" style="height: 1px;"></div>

</div>


<div class="clear" style="height: 1px;"></div>

Arnaud
11-25-2011, 11:34 AM
Is your code in different pages? It looks a mess...

I didn't really investigate but from what I can see from the above code, you can't have a session_start() in the middle of a page.

From php.net: To use cookie-based sessions, session_start() must be called before outputing anything to the browser.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum