How to get same feature as Digitalpoint have

Discussion in 'PHP' started by vishalonne, Aug 28, 2012.

  1. #1
    Hello

    I want the same feature as Digitalpoint have.
    If I Go on PHP forum and try to start new discussion without doing login process, it takes me to the login page and if enter my valid login id and password it directly takes me to page where I can start posting new post.

    In my site I want to implement same facility.
    I have already done login part if user click with doing login process on a link which requires login validation process then user will get a message for Enter login information....
    Now I am not find the way "How I will take the user back to that same page where he/she want to go after his/her valid login".

    Need guidance me to do this

    Thank you for any support…
     
    vishalonne, Aug 28, 2012 IP
  2. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #2
    Interesting problem I normally ride on the CMS doing this as part of its coding :D.

    If I was coding manually (like in your situation) I'd implement a boolean on server side to check if the client has a session cookie (isset) and if not (not signed in) return a login link in the submit forms on the fly, but making sure that there is no type in form on screen so client can't type and hence would not lose any text.

    Client would click on submission link only to be taken to a login page. The login page (via a boolean conditional) seeks the clients browser for a session cookie and if negative (since he/she hasn't logged in yet) would retrieve the referrer URI
    rawurldecode($_SERVER['HTTP_REFERER']); 
    PHP:
    and write this via the setcookie function to the client browser.

    Since we know that the client came from a post to thread page because the boolean argument coded on that page returned negative for a session cookie and added links to the login page instead of opening up a typein box to post (if the session cookie was present - positive boolean return.) we know that when they login the earlier cookie sent to their browser has the URI for the post to thread page.

    The client would naturally login via your existing framework and if the login was successful (right username, password, etc) you would need to add a boolean on success to read the earlier rawurldecode($_SERVER['HTTP_REFERER']); cookie which if present another boolean conditional can redirect on the fly to the page written to the cookie, (the post to thread page referrer URI).

    Client would experience the redirect to the original post to thread page and upon success a boolean could be implemented to delete the URI referrer cookie or you could code the cookie to expire in a short time limit (depending which is easer to code:))

    To note if the browser has cookies disabled a small java script could pop up a message to ask client enable cookies in order to continue as a safety buffer for login and for the redirect script.



    Hope this helps good luck with it!




    ROOFIS :cool:
     
    ROOFIS, Aug 30, 2012 IP
  3. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #3
    re:
    Forgot to add regarding that second boolean if it returned negative (no rawurldecode($_SERVER['HTTP_REFERER']); cookie) then client would continue to their membership page instead of being redirected to the post to thread page that they wanted to contribute to.



    I know the logistics here are pretty rough and could most probably do with a bit of finessing but I think you'd be able to deduce the gist of what I've written here to code,

    or simpler still find an open source class (http://phpclasses.org which has been coded for something like this already :cool: ;)
    just my 2 cents worth!

    good luck with it :)




    ROOFIS
     
    ROOFIS, Aug 30, 2012 IP
  4. vishalonne

    vishalonne Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Thanx Roofis for considering my problem
    Actually I tried a lot but I am confused how to implement the code (precisely where to implement)
    
    include 'dbconnection.php';
    include 'functions.php';
    if(login_check() === false)
    {
        $_SESSION['destination'] = $_SERVER['REQUEST_URI'];
        header('Location: login.php');
    }
    else
    {
        if(isset($_SESSION['destination']))
        {
            unset($_SESSION['destination']);
        }
        #
        # restricted page
        # include/echo or just redirect
        echo 'hello';
    }
    
    PHP:
    If you can take some botheration to review my code then here it is -
    at top of the page
    <?php
    if(!isset($_SESSION))include "functions.php";
    ?>
    then some script and html ....
     <div class="panel_container">
    	<?php
            if(!defined('HOST'))include 'dbconnection.php';
             if(login_check($mysqli) == true){ ?>
             <div id="nav" class="image002-03">
             <span id="smalltext" style="bottom: 0px; margin-bottom: 0px; padding-bottom: 0px; font-family: Calibri; font-size: large; text-align: center;">Service Menu</span>
            <ul id="ul1" class="serviceul">
                <li class="serviceli"><a href="unsolvedCSQPXI.php">Unsolved Question Papers</a></li>
                <li class="serviceli"><a href="unsolvedCSSPXI.php">Unsolved Sample Paper</a></li>
                <li class="serviceli"><a href="">Projects Samples</a></li>
                <li class="serviceli"><a href="">Presentations</a></li>
                <li class="serviceli"><a href="downloads.php">Solved Materials</a></li>
                <li class="serviceli"><a href="">Uploads</a></li>
                <li class="serviceli"><a href="forum.php">Take Test</a></li>
                <li class="serviceli"><a href="">Live Chat</a></li>        
            </ul>
    </div>
    <?php
    }
    else{?>
    
    <div id="nav" class="image002-03">
            <span id="smalltext" 
                style="bottom: 0px; margin-bottom: 0px; padding-bottom: 0px; font-family: Calibri; font-size: large; text-align: center;">Service Menu</span>
            <ul id="ul1" class="serviceul">
                <li class="serviceli"><a href="unsolvedCSQPXI.php">Unsolved Question Papers</a></li>
                <li class="serviceli"><a href="unsolvedCSSPXI.php">Unsolved Sample Paper</a></li>
                <li class="serviceli"><a href="">Projects Samples</a></li>
                <li class="serviceli"><a href="">Presentations</a></li>
                <li class="serviceli"><a href="invalidentry.php">Solved Materials</a></li>
                <li class="serviceli"><a href="invalidentry.php">Uploads</a></li>
                <li class="serviceli"><a href="invalidentry.php">Take Test</a></li>
                <li class="serviceli"><a href="invalidentry.php">Live Chat</a></li>        </ul>
    </div>
    <?php } ?>	
    	<div class="image002-07">
    		Site Map</div>
    	<div class="image002-08">
    	    Advertisement
    		</div>
    	<div class="image002-09">
    		Advertisement</div>
    	<div id="content" class="image002-10">
    	</div>
    PHP:
    and this the file where login authentication is processed -

    <?php
    include 'dbconnection.php';
    include 'functions.php';
    //sec_session_start(); // Our custom secure way of starting a php session. 
     
    if(isset($_POST['email']) && isset($_POST['p'])) { 
       $email = $_POST['email'];
       $password = $_POST['p']; // The hashed password.
       if(login($email, $password, $mysqli) === true) {
          // Login success
          include("XICS.php");
       } else {
          // Login failed
          header('Location: login.php?error=1');
       }
    } else { 
       // The correct POST variables were not sent to this page.
       echo 'Invalid Request';
    }
    
    ?>
    PHP:
    You see live on http://www.cbsecsnip.in/csnip/XICS.php
     
    vishalonne, Aug 30, 2012 IP
  5. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #5
    foo-barred..................................
     
    Last edited: Aug 30, 2012
    ROOFIS, Aug 30, 2012 IP
  6. vishalonne

    vishalonne Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    Thank you again
    1. XICS.php is not client register page, it is a page where all the links are shown for class XI Students of computer Science, this page contain few link which require login authentication. If they click on those link (solved materials) then they will get an error or information message page. Then they can go for login on home page or from XICS.php (I am adding login code on XICS.php page now) then after login they should come back again on the page from where they gone for login.

    Now for the time being I redirected on XICS.php because I don't able to figure out how to send the url of the page from where they gone for login.
     
    vishalonne, Aug 30, 2012 IP
  7. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #7
    foobar Ed ;)
     
    Last edited: Aug 30, 2012
    ROOFIS, Aug 30, 2012 IP
  8. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #8
    right ok got you (kind of) just ignore my post just below yours.
     
    ROOFIS, Aug 30, 2012 IP
  9. vishalonne

    vishalonne Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #9
    So Roofis...! What do you think is there any hope?
     
    vishalonne, Aug 30, 2012 IP
  10. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #10
    As I was saying in the first post when the session cookie is added to the clients browser at login and if you cant write the rawurldecode($_SERVER['HTTP_REFERER']); to it you can add a rawurldecode($_SERVER['HTTP_REFERER']); temp cookie with the login process which upon successful login can be read to retrieve the referrer URI (the clients previous page to redirect to after login).

    This URI can be phrased/passed though into a php redirect script to send the client back to the page they where at prior to logging in, only this time they are logged in! You can set the rawurldecode($_SERVER['HTTP_REFERER']); temp cookie to expire or delete it when they arrive on the redirected page.

    Hope this helps,


    ROOFIS
     
    Last edited: Aug 30, 2012
    ROOFIS, Aug 30, 2012 IP