dynamically remove elements in a webpage after user login

Discussion in 'PHP' started by mohitspage, May 30, 2012.

  1. #1
    hey fellas..
    im a newbie to web development but quite familiar with web programming languages..
    i have created a page with username and password field at the right top of the page..
    what i want is that it should be removed after user authentication..
    for authentication im using php and mysql.....
    here is a sample of what i am doing...
    http://59.177.115.68/
    the above website works in the following way
    index.html [username,password] --> login.php (authentication from databse) --> login.html

    what i want is that the username and password fields are to be removed after the authentication is done from all pages...
    help appreciated..:)
    thanks in advance..
     
    mohitspage, May 30, 2012 IP
  2. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #2
    If your modding a CMS like wordpress and don't want to interfere with it's core coding, a quick and dirty method can be achieved with css,
    
    #login {
        display:none;
    }
    
    Code (markup):
    just make a id css hook on the login credentials html and add code to your default .css file. :)






    ROOFIS
     
    ROOFIS, May 30, 2012 IP
  3. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #3
    First I would name each file with a php extension (index.php, about.php, etc).

    At the top of each page (before any spaces or output of any text) I'd put session_start(); to enable sessions and use the $_SESSION array to keep track of whether or not the user is logged in.

    Then on login.php:
    
    <?php
    session_start();
    
    $_SESSION['loggedIn'] = 0; 
    $user = $_POST['user'];
    $pass = $_POST['pass'];
    
    // Code to check for valid login
    // If valid user, set $_SESSION['loggedIn'] = 1;
    
    $_SESSION['loggedIn'] = 1;
    
    header("Location: where-ever.php");
    ?>
    
    PHP:
    Then for your other pages:
    
    <?php
    session_start();
    ?>
    <html>
    <body>
    <!-- whatever HTML -->
    <?php
    if (!$_SESSION['loggedIn']) {
    ?>
    <!-- code for your login box -->
    <?php
    }
    ?>
    </body>
    </html>
    
    PHP:
    Something similar to that should work.
     
    kbduvall, May 30, 2012 IP
  4. mohitspage

    mohitspage Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks guys...
    ill get back after applying bolt the solutions i got...
    n be back with some other questions too....;)
     
    mohitspage, May 30, 2012 IP
  5. mohitspage

    mohitspage Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    @ROOFIS : how can this code help me remove the uname and passed boxes in all the pages??
     
    mohitspage, May 30, 2012 IP
  6. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #6
    kbduvall's come up with a nifty solution which I think will work but if you where just interested in not displaying usernames on top of each page then display:none; added to your default .css file will do the trick. Reason is clients browser will make a call to the css file to phrase the html elements on every page of your site.
    further reading:
    w3schools.com/css/css_display_visibility

    example for DP (if you have firebug for firefox):

    from DP's css file for welcomelink from page source,
    <link rel="stylesheet" type="text/css" href="http://c.dpstatic.com/css.php?styleid=1&amp;langid=1&amp;d=1327657622&amp;td=ltr&amp;sheet=toolsmenu.css,postlist.css,showthread.css,postbit.css,options.css,attachment.css,poll.css,lightbox.css" />

    
    .toplinks ul.isuser li.welcomelink {
        clear: left;
        display: [B][COLOR="#FF0000"]none[/COLOR][/B]; #changed from display:block;
        float: right;
        padding: 3px 4px;
    }
    .toplinks ul.isuser li.logoutlink {
        top: 0;
    }
    .toplinks ul.isuser li a {
        color: #FFFFFF;
        display: [B][COLOR="#FF0000"]none[/COLOR][/B]; #changed from display:block;
        font-weight: bold;
        padding: 3px 4px;
    }
    
    Code (markup):
    produces:

    [​IMG]


    -edit-

    I should of mentioned that this would need to be added as part of a login check as kbduvall mentioned.

    for http://59.177.115.68/ css hook which is usr_login
    
    <?php
    if (isset($_SESSION["loggedIn"])) { 
    echo '<style> 
    #usr_login{
    display: none;
    }
    </style>';
    }
    ?>
    
    PHP:




    :)
     
    Last edited: May 30, 2012
    ROOFIS, May 30, 2012 IP