473,729 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change the login hyper link to logout when successfully logged in

8 New Member
I have a link on my site which obviously says "Login" where users log in.

I would like that link to be changed to "Logout" when the user has successfully logged in and the session has been created and when the user logs out, i would like the link changed back to "Login" without having to refresh the page.

here is my login page
[PHP]<?php

if (is_authed_user ())
{
print ('You are already logged in, <a href="index.php ">click here</a> to go back.');
}
else
{

if (!isset($_POST['submit']))
{
echo "<h2>Memebe r Login</h2><hr />";
// Show the form
include 'includes/login_form.inc. php';
}
else
{
$username = check_input($_P OST['username']);
$password = check_input($_P OST['password']);

// Try and login with the given username & pass
$result = user_login($use rname, $password);

if ($result != 'Correct')
{
echo "<h2>Memebe r Login</h2><hr />";
// Reshow the form with the error
$login_error = $result;
include 'includes/login_form.inc. php';
}
else
{
echo "<h2>Welcom e ".$_SESSION['username']."</h2><hr />";
echo 'Thank you for logging in, <a href="index.php ">click here</a> to go back.';
}
}
}
?>[/PHP] and the function to log the user in if you need it
[PHP]function user_login($use rname, $password)
{
// Try and get the salt from the database using the username
$query = "select salt from users where username='$user name' limit 1";
$result = mysql_query($qu ery);
$user = mysql_fetch_arr ay($result);

// Using the salt, encrypt the given password to see if it
// matches the one in the database
$encrypted_pass = md5(md5($passwo rd).$user['salt']);

// Try and get the user using the username & encrypted pass
$query = "select userid, username, user_level from users where username='$user name' and password='$encr ypted_pass'";
$result = mysql_query($qu ery);
$user = mysql_fetch_arr ay($result);
$numrows = mysql_num_rows( $result);

$userid = $user['userid'];
$user_level = $user['user_level'];

// Now encrypt the data to be stored in the session
$encrypted_id = md5($user['userid']);
$encrypted_name = md5($user['username']);
$encrypted_user = md5($user['user_level']);

// Store the data in the session
$_SESSION['userid'] = $userid;
$_SESSION['username'] = $username;
$_SESSION['user_level'] = $user_level;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name '] = $encrypted_name ;
$_SESSION['encrypted_user '] = $encrypted_user ;


if ($numrows == 1)
{
return 'Correct';
}
else
{
return false;
}
}[/PHP]

all i have for the logout page is a simple session_unset() and session_destroy ()

This seems such a simple task but don't know where to start.

I presume the ajax would go after this in the login form to change the link from login to logout
[PHP]$result = user_login($use rname, $password);[/PHP]
If anyone has any ideas how i would do this i would be very grateful
Feb 15 '08 #1
1 3313
acoder
16,027 Recognized Expert Moderator MVP
Give the link an id. When the user has successfully logged in, i.e. readyState is 4 and you've validated that it's correct, change the link text: document.getEle mentById(linkID ).innerHTML="Lo gout".
Feb 16 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3486
by: Shakun | last post by:
Hi All, This is my 1st posting to this group. Can any1 help me with the "Remember Me" which is there in a login form. Im pasting the code below. Im not able to set a cookie.. Thanks, Shakun Vohra
3
2326
by: Jennifer.Berube | last post by:
okay...so I got this login script and I edited it all and it seems to run fine...IE it listens to the script as far as permissions go when I place a restriction on a page and when you login it redirects. But first it doesn't tell you that you're logged in and doesn't provide a logout feature. And most importantly if I type in a random username and password not listed in the database it doesn't seem to matter it still "lets me login"
0
895
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have a two pages in the locations ~/Folder1/LoggedIn.aspx and ~/Folder2/Services.aspx. Both folders have a web.config file that redirects unauthenticated users to ~/Login.aspx. When a user is logged from ~/Login.aspx they are directed to ~/Folder1/LoggedIn.aspx. There is a hyper link on this page that should direct the user to ~/Folder2/Services.aspx. However, when I click on this link, I am returned to the ~/Login.aspx page. There is...
0
942
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I have a two pages in the locations ~/Folder1/LoggedIn.aspx and ~/Folder2/Services.aspx. Both folders have a web.config file that redirects unauthenticated users to ~/Login.aspx. When a user is logged from ~/Login.aspx they are directed to ~/Folder1/LoggedIn.aspx. There is a hyper link on this page that should direct the user to ~/Folder2/Services.aspx. However, when I click on this link, I am returned to the ~/Login.aspx page. There is...
3
5552
by: burrashiva | last post by:
:( ::) Hello there, I recently started Web Designing with PHP, Javascript and AJAX. I am facing a problem which I will try to explain: If I am successful in conveying the problem to you clearly, could you pl. suggest me some solution? Thank you, Here is the problem details:
1
2135
by: webandwe | last post by:
Hi, Can somebody please show me how to change the connection so I can make it work with my MYSQL database... I just need this login to work then I'm done wiht my project. I don't know what is going on here and is, this far from throughing my laptop into the wall..... I want to change cStr = "DRIVER={Microsoft Access Driver (*.mdb)};" cStr = cStr & "DBQ=" & Server.MapPath("\path\to\database.mdb") & ";" Conn.Open(cStr)
10
4818
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David Smith's. So something is amiss but I don't know what. (BTW, this login script is based on the...
9
7531
by: adweaver | last post by:
Hello All, I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs. The site was built in a folder called mysite.com/test. I coppied this folder a number of times, so I now have mysite.com/test2, mysite.com/test3 etc. Each folder acts as its own landing page. they setup an interface where we can control the upsells presented to the customer;...
22
2872
by: macdalor | last post by:
HI, I hope someone can help. I'm trying to show the username of the logged in user on this menu.inc page and certain pages only when logged in. The result I have with the code below is no username showing, just "Hi !" (the "login" link disappear as planned) and all pages showing (logged and un-logged) thank you for your help <div style="margin-bottom: 0px; margin-left: auto; margin-right: auto; margin-top: 0px; overflow:...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.