Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    $_Session not storing on first attemp

    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 Code:
    <?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;colorscheme=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>

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    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.
    Chuck Norris counted to infinity.
    Twice.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •