Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts

    Trying to build a logout button

    Hello,

    I'm trying to build a logout button, accomplishing the top execution with the button code below it. How do I do something like this? It has me puzzled.

    <a href="/member/frontend/logout.php">Logout</a>

    <FORM><INPUT TYPE="BUTTON" VALUE="button text here" ONCLICK="window.location.href='http://mysite'"></FORM>

  • #2
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts
    I should have said this:

    When a person is on a permission-granted page, I want them to be able to click "Logout" and then be automatically redirected back to my home page. I should have said that right away. Sorry.

  • #3
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Set the form action to the page you want the users to land on.

    <form action="http//:www.myhomepage.com"></form>

    I guess thats all you're asking right?
    Teed

  • #4
    Regular Coder Kevin_M_Schafer's Avatar
    Join Date
    Apr 2011
    Location
    Fairfax, Minnesota, U.S.A.
    Posts
    482
    Thanks
    97
    Thanked 17 Times in 17 Posts
    Teed,

    What about the logout part with the PHP?

  • #5
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts

  • #6
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    As quartzy pointed out, since php is an open source, there are probably tons of free login/logout scripts and tutorials online.
    Teed

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    California
    Posts
    201
    Thanks
    30
    Thanked 8 Times in 8 Posts
    An example of a logout page can be as follows: (simply put)


    logout.php
    PHP Code:
    <?php

    session_destroy
    ();

    header ('Location: http://your-redirect-page.com/');

    ?>
    When a user clicks the logout link, it will automatically send them to your desired page instantly, and clear the session (logout the user).

    But in order for this to work, a session needs to be started from the get go!!

  • #8
    New Coder
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Assuming we are attempting to log out of a PHP Session; from a security perspective I've found it safer to re-initialize the Session rather then merely destroying it before logging out.

    PHP Code:
    session_start();
    //set some $_SESSION[$values]
    $_SESSION = array();
    session_regenerate_id(true);
    session_destory(); 
    In this manner the first Session is replaced with a second, empty, Session before logging out to remove all traces of the first Session.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •