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
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
Share on other sites

Then, when you log your users in set a session variable (eg; $_SESSION['is_logged_in']) to true. You can then use this to track whether or not your users are logged in, from there its just a simple if statement like I just showed you.

Link to comment
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
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
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
Share on other sites

To tell the truth, no I don't know how it works.

 

Then your going to have a pretty hard time using it. Did you write the system from a tutorial or just download it from somewhere? Are you actually interested in learning php or just want this stuff working?

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.