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 4 of 4

Thread: Php Tags Basics

  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Php Tags Basics

    Hi friends I cannot understand why we need the close curly braces in opening and closing php tags.

    kindly have the code below as the referrence:
    im trying to implement this with a login script where user can be a guest,ordinary member and an admin...


    <?php
    include "dbc.php";
    if (isset($_SESSION['user_id'])) {?>



    <span class="style2"><a href="mysettings.php">Edit Profile</a> | <a href="logout.php">Logout </a></span>

    <?php
    if (checkAdmin()) { ?>
    | <span class="style2"><a href="admin.php">Control Panel</a></span>


    <?php
    }
    } else {
    ?>
    <span class="style2"><a href="login.php">Login</a></span>
    <?php
    }
    ?>

    so that if user is admin, Control Panel will be before edit Profile and Logout...
    the visual thing is like the links below..

    if admin:

    Control Panel | Edit Profile | Logout

    if not admin:

    | Edit Profile | Logout

    the implementation should be easy and the logic is very simple...im just having a problem with the php syntax...can u explain a little about the php tags...closed after curly braces etc..THanks Much!

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Its NOT that the curly brace must follow the php tag, its that you 'dropped' out of php.

    the following would need no curly braces
    start php
    do some coding
    drop out of php
    do some html
    start php again

    while this
    start php
    some condition { this is the opening brace for the condtion
    do some php
    } closing brace for the condtion

    and finally
    start php
    some condition {
    drop out of php
    some html
    start php
    }

    clear as mud?

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    If the HTML blocks are very small, then it'd be better to use a single PHP tag and convert all html to strings, like

    PHP Code:
    <?php
    include "dbc.php";
    if (isset(
    $_SESSION['user_id'])) {

    echo 
    '<span class="style2"><a href="mysettings.php">Edit Profile</a> | <a href="logout.php">Logout </a></span>';


    if (
    checkAdmin()) { 

    echo 
    '| <span class="style2"><a href="admin.php">Control Panel</a></span>';

    }
    } else {

    echo 
    '<span class="style2"><a href="login.php">Login</a></span>';

    }
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yup..thats what ive done after I was advised by a friend..


    the code below:

    <?php
    include "dbc.php";


    if (isset($_SESSION['user_id']))
    {


    if (checkAdmin())
    {



    echo '<span class="style2"><a href="admin.php">Control Panel | </a></span>';
    }

    echo '<span class="style2"><a href="mysettings.php">Edit Profile</a> | <a href="logout.php">Logout </a></span>';


    }

    else

    {

    echo '<span class="style2"><a href="login.php">Login</a></span>';

    }


    ?>

    thanks anyway


  •  

    Posting Permissions

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