开发者

PHP generated Menu problem on XHTML 1 webpage

I am having a problem with a menu that is generated depending on whether a PHP session variable called "login" is true or false.

What it should do is when someone first navigates to the page. They will not be logged on so they will have a non logged in user menu displayed however when they login some of the menu items will change.

My menu works ok when you goto login page and 开发者_开发百科login however on my homepage where you start from my menu is getting messed up by some bits of php code which are being displayed on my menu for no reason. Its the same code but it does not work.

I have checked for accidental "{]" or () or '' but there is none. It is really driving me bonkers

Here is the code

php session_start(); //check if session variable has been initialised if not then login set to false making standard menu layout. if (isset($_SESSION["login"]) $_SESSION["login"] = ] $_SESSION["login"]; else $_SESSION["login"] = false;

<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico">
<link rel="Stylesheet" href="css/style.css" media="Screen and (min-device-width: 481px)" type="text/css" title="Default"/>
<link type="text/css" rel="Stylesheet" media="only Screen and (max-device-width: 480px)" href="css/mobile.css" />
<title>Heavy Metal - User Experience Jobs</title>

<meta name="author" content="anon"/>

<div id="banner">

    <img src="images/banner.jpg"  title="Banner Image" height="180" width="750"/> 
</div>

<div id="topmenu">
    <ul class="menu">
        <li>
            <ul class = "submenu1" id = "sm_1">
                <li><a class="link1" href="index.html">Home</a>

                </li>

                <li><a href = "php/latestjobs.php" class="link2" >Latest Jobs</a>

                </li>

                <li><a href = "search.html" class="link3">Search Jobs</a>

                </li>

                <li>
                <a href = "login.html" class="link4">Login</a>
                </li>

                <li>
                <?php
                if ($_SESSION["login"] == true)
                    echo    ('<a href = "php/j_details.php" class="link4">Check Details</a>');}
                else if ($_SESSION["login"] == false)
                    echo    ('<a href = "register.html" class="link4">Register</a>');
                ?>
                </li>
            </ul>
        </li>
    </ul>
</div>

Thankyou for your time!


You've called your file index.html. Without the .php file extension, the server doesn't know that it's supposed to be a PHP script you want it to process, so it just returns the page verbatim, with all the <?php sections left in place.


U have too much syntax errors and other...

Replace this code:

<?php
 session_start();
 //check if session variable has been initialised if not then login set to false making standard menu layout.
 if (isset($_SESSION["login"])
 $_SESSION["login"] = true;
 else
 $_SESSION["login"] = false;
 ?>

with this:

<?php
 session_start();
 //check if session variable has been initialised if not then login set to false making standard menu layout.
 if (isset($_SESSION["login"])) {
 $_SESSION["login"] = true;
 }
 else {
 $_SESSION["login"] = false;
 }
 ?>

and this:

                    if ($_SESSION["login"] == true)
                    echo    ('<a href = "php/j_details.php" class="link4">Check Details</a>');}
                else if ($_SESSION["login"] == false)
                    echo    ('<a href = "register.html" class="link4">Register</a>');

with:

<?php
if ($_SESSION["login"] == true) {
echo    ('<a href = "php/j_details.php" class="link4">Check Details</a>');}
else if ($_SESSION["login"] == false) {
echo    ('<a href = "register.html" class="link4">Register</a>'); }
?>

Understood? I hope that will help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜