Session will not register from index.php to search.php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fjm
    Contributor
    • May 2007
    • 348

    Session will not register from index.php to search.php

    Hello all,

    I have 2 files. index.php which is a log in page and a search page. After the user logs in they are taken to the search page by way of a checklogin script that verifies the user.

    My index page has two fields:

    customer
    password

    Here are the contents of both of my files. I'm sure I am missing something here but 4 hours later and I am stll in the same place.

    index.php
    [PHP]
    <?php session_start() ; ?>
    </head>
    <body>
    <form method="post" action="CheckLo gin.php">
    <div style="text-align: left;">
    <table style="margin: 0 auto;">
    <tr>
    <td><!-- start of dfar body -->
    <table class="table">
    <tr>
    <td><img src="images/logo.gif" alt="" /></td>
    </tr>
    <tr>
    <td><hr /></td>
    </tr>
    <tr>
    <td align="center"> <h4>Client Login</h4></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td class="searchRe ports">
    <table cellpadding="5" cellspacing="5" >
    <tr>
    <td>Customer Number:</td>
    <td colspan="3"><in put class="taskedit _tf" size="20" name="customer" /></td>
    </tr>
    <tr>
    <td>Password: </td>
    <td colspan="3"><in put class="taskedit _tf" size="20" name="password" /></td>
    </tr>
    <tr>
    <td colspan="3"><in put type="image" src="images/query.gif" /></td>
    <td><?php echo @$_SESSION['loginerr']; ?></td>
    </tr>
    </table>
    </td>[/PHP]

    search.php
    [PHP]
    <?php session_start() ; ?>
    <?php echo $customer; ?>
    [/PHP]

    checklogin.php
    [PHP]
    <?php
    session_start() ;
    ob_start();
    include "Persist.ph p";

    $customer=$_POS T['customer'];
    $password=$_POS T['password'];
    $sql = "SELECT * from customer where bla bla....";

    $result=mysql_q uery($sql);
    // Mysql_num_row is counting table row
    $count=mysql_nu m_rows($result) ;
    // If result matched $employee and $password, table row must be 1 row
    if($count==1){
    // Register $employee, $password and redirect to file "Search.php "
    session_registe r("customer") ;
    session_registe r("password") ;
    header("locatio n:Search.php?") ;
    }
    else {
    if(!session_is_ registered("cus tomer")){
    header("locatio n:index.php");
    }
    $_SESSION['loginerr'] = "Incorrect Password";
    }
    ob_end_flush();
    ?>
    [/PHP]

    Can someone please shed some light as to what I need to do to pass the customer number from the checklogin script to the search page?

    Thanks!!

    Frank
  • fjm
    Contributor
    • May 2007
    • 348

    #2
    I got it. hehe. :)


    It was on line 14 of checklogin.php. I changed session_registe r() to [PHP]$_SESSION['customer'] = $customer;[/PHP] and it worked.
    I stuck this into the search.php script:

    [PHP] <?php
    if(!isset($_SES SION['customer'])){
    echo 'No Data';
    }else{
    echo $_SESSION['customer'];
    }
    ?>[/PHP]
    and it helped me to see what was happening.

    If there is a better way to do this, please advise..

    Thanks guys!

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Frank.

      Originally posted by fjm
      [PHP] <?php
      if(!isset($_SES SION['customer'])){
      echo 'No Data';
      }else{
      echo $_SESSION['customer'];
      }
      ?>[/PHP]
      You can also do this:[code=php]
      echo (isset($_SESSIO N['customer'])
      ? $_SESSION['customer']
      : 'No Data'
      );
      [/code]

      I like to break it up on multiple lines to make it easier to read, but you can put the whole thing on one line if you want.

      http://us2.php.net/manual/sl/languag...comparison.php (look for 'ternary' operator).

      Comment

      • fjm
        Contributor
        • May 2007
        • 348

        #4
        Originally posted by pbmods
        Heya, Frank.



        You can also do this:[code=php]
        echo (isset($_SESSIO N['customer'])
        ? $_SESSION['customer']
        : 'No Data'
        );
        [/code]

        I like to break it up on multiple lines to make it easier to read, but you can put the whole thing on one line if you want.

        http://us2.php.net/manual/sl/languag...comparison.php (look for 'ternary' operator).
        Thanks for the link and advice pbmods.. I will research that now! :)

        Comment

        Working...