Jump to content

[SOLVED] Session help


aznkidzx

Recommended Posts

Okay my navigation menu, I have all these regular things. I also have Login Register and Logout. This is the code for my navigation menu.

 

            <ul id="navigation" name="navigation">
       	    	<li><a href="index.html">home</a></li>
                <li><a href="about.html">about</a></li>
                <li><a href="portfolio.html">portfolio</a></li>
                <li><a href="contact.php">contact</a></li>

                <li><a href="register.php">register</a></li>
                <li><a href="login.php">login</a></li>
                <li><a href="logout.php">logout</a></li>

 

I want to make it so that only when people are logged in, the logout navigation is there. How do I do so?

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/
Share on other sites

So you need to sort out your login system too? Why not do that first? Once your tracking users via sessions its easy enough to display different things to different users based on whether or not there logged in. eg;

 

session_start();

if ($_SESSION['is_logged_in'])) {
  // display data for logged in users
} else {
  // display data for users who aren't logged in.
}

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748953
Share on other sites

Wherever you want to make a decision about whether or not something should be outputed based on whether or not your user is logged in or not. eg;

 

session_start();

if ($_SESSION['is_logged_in'])) {
  // display data for logged in users
} else {
  // display data for users who aren't logged in.
}

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748988
Share on other sites

So in my navigation menu, I put this? Wait also sorry for being stupid and useless.

            <ul id="navigation" name="navigation">
       	    	<li><a href="index.html">home</a></li>
                <li><a href="about.html">about</a></li>
                <li><a href="portfolio.html">portfolio</a></li>
                <li><a href="contact.php">contact</a></li>

                <li><a href="register.php">register</a></li>
                <li><a href="login.php">login</a></li>
<?php
session_start();

if ($_SESSION['is_logged_in'])) {
  // display data for logged in users
} else {
  // display data for users who aren't logged in.
}
?>
                <li><a href="logout.php">logout</a></li>

            </ul>

 

--------------

I just tried that code and this is the error

 

Parse error: syntax error, unexpected ')' in /home/a7856302/public_html/portfolio/index.html on line 29

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748991
Share on other sites

Based on your example above.

 

<?php session_start(); ?>
<ul id="navigation" name="navigation">
  <li><a href="index.html">home</a></li>
  <li><a href="about.html">about</a></li>
  <li><a href="portfolio.html">portfolio</a></li>
  <li><a href="contact.php">contact</a></li>
  <li><a href="register.php">register</a></li>
  <li><a href="login.php">login</a></li>
  <?php
    if (isset($_SESSION['is_logged_in'])) {
      echo "  <li><a href=\"logout.php\">logout</a></li>";
    }
  ?>

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-748993
Share on other sites

Both. I downloaded.

 

That doesn't really answer the main gist of the question. What Im getting at is basically this. If you are interested in learning php then simply downloading code is likely to make things harder. You need to build your login system from scratch so as you understand how it works so you can make the desired changes you may need.

 

If your not acxtually interested in learning php and just want this stuff working, Id suggest you find a programmer.

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749023
Share on other sites

I want to learn too.

 

Then Id suggest finding a decent 'php login' tutorial and building your own login system. Even though the objective of your post was quite simple, it seems to me your trying to run before you can even walk.

 

Also, how do I open php.exe?

 

You don't open it. It is used to execute command line php scripts. eg;

 

php.exe mysript.php

Link to comment
https://forums.phpfreaks.com/topic/142864-solved-session-help/#findComment-749033
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.