SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    having difficulty passing session variable

    I have made a simple login using the following code.
    PHP Code:
    <?php
        
    include 'db.inc.php';
        if(isset(
    $_POST['submit']))
        {
            
    $email $_POST['email'];
            
    $acode $_POST['acode'];
            
            
    $sql "SELECT acode FROM dealers WHERE email='$email'";
            
    $result = @mysql_query($sql);
            
            if (!
    $result) {
                exit(
    '<p>Error performing query: ' .
                
    mysql_error() . '</p>');
            }
            
            while(
    $row mysql_fetch_array($result)){
                
    $bcode $row['acode'];
            }
            if(
    $bcode == $acode)
            {
                
    $_SESSION['authorized'] = TRUE;
            }
        }
    //end of if isset submit
        
    if(isset($_REQUEST['logout']))
        {
            unset(
    $_SESSION['authorized']);
        }
        if(isset(
    $_SESSION['authorized']))
        {
    ?>        
    DISPLAY THE PAGE CONTENT
    Part of the page content to be displayed is a menu. One of the links leads to a file called nrb.php.

    What I want to do is get nrb.php to either display its contents or redirect back to index.php to login, depending on whether or not the dealer is logged in; but I can't get it to work.

    No matter what I try, typing localhost/folder/nrb.php into the address bar of the browser just shows it to me.

    I was basing it on various incarnations of, "if the session variable is not set to true, send them to index.php to login," but no joy.

    Any answers greatly appreciated.

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where are you putting session_start()

    it shoupld be very first line on EACH AND EVERY PAGE, where you want to use session.
    (first line means before anything goes out to browser and before you start using SESSION VARIABLES)
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Member
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I didn't have start_session at the top of the index page. Thanks for the prompt reply as well. Thought this one was going to keep me awake tonight!

  4. #4
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to help you.
    enjoy you night
    ---------------------------
    Errors = Improved Programming.
    My Site


Bookmarks

Posting Permissions

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