1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Login and Logout using Sessions and Cookies

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

  1. dean8710

    dean8710 New Member

    shabbir - admin:

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

    shabbir Administrator Staff Member

    What previous data you want to clear? Do you want to restrict previous page with back button?
     
  3. dean8710

    dean8710 New Member

    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

    The best is to session expire the page rather than trying those JS tricks.
     
  5. dean8710

    dean8710 New Member

  6. Scripting

    Scripting John Hoder

    This tut is really awardworthy :D
     
  7. shellz

    shellz New Member

    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

    hi! glad to be here!
     
  9. dean8710

    dean8710 New Member

    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

    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

    Can you say what did not work?
     
  12. shellz

    shellz New Member

    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

    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

    so cool explained... happy to read it ,thanx for this bro
     
  15. javeed_nizar

    javeed_nizar New Member

    how to prevent user multiple login with single account
     
  16. shabbir

    shabbir Administrator Staff Member

    Create sessions based on user's current details like IP and then check if already logged in or session is live.
     

Share This Page