Login and Logout using Sessions and Cookies

Discussion in 'PHP' started by shabbir, Jun 15, 2005.

  1. dean8710

    dean8710 New Member

    Joined:
    Aug 3, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Petaling Jaya
    shabbir - admin:

    how to clear all the previous data?
    how to restrict the previous page?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What previous data you want to clear? Do you want to restrict previous page with back button?
     
  3. dean8710

    dean8710 New Member

    Joined:
    Aug 3, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Petaling Jaya
    i found the solution to 'disable BACK button:

    <script type="text/javascript">
    window.history.forward();
    function noBack(){ window.history.forward(); }
    </script>
    </head>
    <body onLoad="noBack();" onpageshow="if (event.persisted) noBack();" onUnload="">

    the problem is, when i clicked on 'log out' link, it will redirect user to index.html.
    then, i clicked 'back' button, it will go back to previous page where, member area, some php code make looks ugly..

    'undefined bla bla bla on line bla bla bla', which mean i already unset all data

    is the solution of disabled the 'back' button is good?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The best is to session expire the page rather than trying those JS tricks.
     
  5. dean8710

    dean8710 New Member

    Joined:
    Aug 3, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Petaling Jaya
  6. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    This tut is really awardworthy :D
     
  7. shellz

    shellz New Member

    Joined:
    Sep 26, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    a student
    Location:
    Indonesia
    Hi Mr Shabbir..
    I'm really new in php.. i've tried this code, but it doesn't work.. Can you please help me?
    Thanks..:nice:
     
  8. paulelliott

    paulelliott New Member

    Joined:
    Sep 26, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi! glad to be here!
     
  9. dean8710

    dean8710 New Member

    Joined:
    Aug 3, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Petaling Jaya
    im sorry, above code is not working, btw above code is to disabled right click of the mouse so, user cannot copy using 'right-click', and view the source code.

    here is the right code:


    <!-- disable right click -->
    <script>
    var isNS = (navigator.appName == "Netscape") ? 1 : 0;
    if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
    function mischandler(){
    return false;
    }
    function mousehandler(e){
    var myevent = (isNS) ? e : event;
    var eventbutton = (isNS) ? myevent.which : myevent.button;
    if((eventbutton==2)||(eventbutton==3)) return false;
    }
    document.oncontextmenu = mischandler;
    document.onmousedown = mousehandler;
    document.onmouseup = mousehandler;
    </script>
    <!-- disable right click -->
     
  10. dean8710

    dean8710 New Member

    Joined:
    Aug 3, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Petaling Jaya
    im sorry, above code is not working, btw above code is to disabled right click of the mouse so, user cannot copy using 'right-click', and view the source code.

    here is the right code:

    <!-- disable right click -->
    <script>
    var isNS = (navigator.appName == "Netscape") ? 1 : 0;
    if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
    function mischandler(){
    return false;
    }
    function mousehandler(e){
    var myevent = (isNS) ? e : event;
    var eventbutton = (isNS) ? myevent.which : myevent.button;
    if((eventbutton==2)||(eventbutton==3)) return false;
    }
    document.oncontextmenu = mischandler;
    document.onmousedown = mousehandler;
    document.onmouseup = mousehandler;
    </script>
    <!-- disable right click -->
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Can you say what did not work?
     
  12. shellz

    shellz New Member

    Joined:
    Sep 26, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    a student
    Location:
    Indonesia
    I am trying to make a login form and i've tried the coding that u gave... But it doesn't work.. Everytime I try to run the program "Parse error: syntax error, unexpected $end in C:\xampp\htdocs\login.php on line 89" always comes out.. i change the document of index into index1 as i also have another document in htdocs folder, but i also change the script in login.php
    Code:
    if ($username=="" or $password=="" )
    	{
    		echo "<h1>Username or password is blank</h1>";
    		clearsessionscookies();
    		header("location: login.php?returnurl=$returnurl");
    	}
    	else
    	{
    		if(confirmuser($username,md5($password))) // As pointed out by asgard2005
    		{
    			createsessions($username,$password);
    			if ($returnurl<>"")
    				header("location: $returnurl");
    			else
    			{
    				header("Location: [B]index1.php[/B]"); (this one from index.php into index1.php)
    			}
    		}
    		else
    		{
    			echo "<h1>Invalid Username and/Or password</h1>";
    			clearsessionscookies();
    			header("location: login.php?returnurl=$returnurl");
    		}
    	}
    	break;
    case "logout":
    	clearsessionscookies();
    	header("location: index1.php"); (from index.php into index1.php)
    	break;
    
    Does it gives any effect? thanks for your explanation..
     
    Last edited by a moderator: Sep 30, 2011
  13. bobwarner01

    bobwarner01 New Member

    Joined:
    Oct 18, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    USA
    Home Page:
    http://www.checkwv.com/
    Sessions and Cookies are really nice interesting topic to cover. Thanks for sharing mate. Actually i was searching the coding that you given, But now its all clear. I found 2-3 but was not applicable
     
  14. iMustBeAlien

    iMustBeAlien New Member

    Joined:
    Nov 9, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Marse
    Home Page:
    http://cgmageek.in
    so cool explained... happy to read it ,thanx for this bro
     
  15. javeed_nizar

    javeed_nizar New Member

    Joined:
    Jun 26, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    how to prevent user multiple login with single account
     
  16. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Create sessions based on user's current details like IP and then check if already logged in or session is live.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice