Jump to content

login pages


adaywalkr

Recommended Posts

Hello people!

I installed and modified a login script on my website.. it works fine, but when I'm logged in, it redirects me to the index page. That's normall. But what I want now is to make my website different for people that are registered.

For example that when your logged in, there are more options in the menu like "My Account" and things like that.

And if your logged in some parts on pages will reveal more text then the standard guest page.

I was wondering if this is hard?
I guess it's not.. but I recently started with php so I don't know how to do it.

Thanx in advance
Link to comment
Share on other sites

That's pretty simple.

If you use cookies:
[code]
<?php
//stuff available to everyone here

if(isset($_COOKIE['logged'])){
//add my account logged in only stuff here
}
?>
[/code]

For sessions:
[code]
<?php
//stuff available to everyone here
if(isset($_SESSION['logged'])){
//add my account logged in only stuff here
}
?>
[/code]

Just changed logged to whatever your cookie or session is called when the user logs in.
Link to comment
Share on other sites

Well, you don't state what variables you set once a user is logged in so it's impossible to give any specific example. But, assuming you have a session variable  called $_SESSION['loggedin'] and have it set to one if the user is logged in and 0 otherwise, just create your menu something like this:

[code]<?php
echo "<a href=\"link1.htm\">Menu Item 1</a><br />";
echo "<a href=\"link2.htm\">Menu Item 2</a><br />";
echo "<a href=\"link3.htm\">Menu Item 3</a><br />";
echo "<a href=\"link4.htm\">Menu Item 4</a><br />";
if ($_SESSION['loggedin']==1) {
 echo "<a href=\"link5.htm\">Menu Item 5</a><br />";
 echo "<a href=\"link6.htm\">Menu Item 6</a><br />";
}
?>[/code]
Link to comment
Share on other sites

Thanks for the replies.
In the script itself there is a php file called "logged_in.php" and this that's where it should lead you after you logged in.

[code]
<?php
include('config.php');
if(!isset($_SESSION['user'])) {
header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Logged in with succes!</title>
</head>
<body>
<p>Welcome,
  <?=$_SESSION['user']?>
</p>
<p>--&gt; <a href="logout.php">Logout</a> </p>
<p>&nbsp;</p>
</body>
</html>[/code]


And it works with me if I put this in my menu:

[code]
<?php
include('config.php');
if ($_SESSION['user']) {
echo "It WOrks !!!";
}
?>[/code]

It works.. but it shows this error:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/website/domains/website.com/public_html/index.php:8) in /home/website/domains/website.com/public_html/session.php on line 2
Link to comment
Share on other sites

That error is there because I insered this code into my home page:

[code]<?php
include('config.php');
if ($_SESSION['user']) {
echo "It WOrks !!!";
}
?>[/code]

It does work.. but it gives that error before the text

I think it's because of the include before the session... but the include has to be there or it won't work :-[
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.