1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

redirect guest to login page

Discussion in 'Social Networks' started by gree124, May 29, 2010.

  1. #1
    Is social Engine network has any plugins or coding that redirect guest to login page and guest can;t see home page.

    click here for example now guest should redirect to login page


    above is not my site it's just example
     
    gree124, May 29, 2010 IP
  2. Earnsite

    Earnsite Peon

    Messages:
    11
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What language is the website coded in?
     
    Earnsite, May 29, 2010 IP
  3. gree124

    gree124 Well-Known Member

    Messages:
    721
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #3
    dude it's php
     
    gree124, May 29, 2010 IP
  4. Earnsite

    Earnsite Peon

    Messages:
    11
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    session_start();

    function logged_in() {
    return isset($_SESSION['user_id']);
    }

    function sendto( $location = NULL ) {
    if ($location != NULL) {
    header("Location: {$location}");
    exit;
    }
    }

    if (!logged_in()) {
    sendto("login.php");
    }


    That will start a session, then if the user doesn't have a stored user_id in the session then he's not logged in so send him to the login page.
    The user_id can be anything, but make sure your logged in members have them in their session else they'll be redirected aswell.
    Hope that helps.
     
    Earnsite, May 29, 2010 IP
  5. gree124

    gree124 Well-Known Member

    Messages:
    721
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #5



    this script should be add in home.php right?
     
    gree124, May 29, 2010 IP
  6. Earnsite

    Earnsite Peon

    Messages:
    11
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm not sure how your website is organised, so i can't tell you exactly where to put it.
    The best way would be to put:

    session_start();

    function logged_in() {
    return isset($_SESSION['user_id']);
    }

    function sendto( $location = NULL ) {
    if ($location != NULL) {
    header("Location: {$location}");
    exit;
    }
    }

    In a seperate .php file, call it something like "session.php" and save it to your includes folder. Then on any page you want people to be logged in for you put this at the very top:
    <?php require_once("includes/sessions.php"); ?>
    if (!logged_in()) {
    sendto("login.php");
    }

    That bit of code needs to be at the very top though, before any html (and prefferably before any processing).

    Hope that helps.
     
    Earnsite, May 29, 2010 IP
  7. websitedevelopment

    websitedevelopment Peon

    Messages:
    231
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    hey,

    I believe that we are discussing above social networking, so could you clarify me this one?
     
    websitedevelopment, May 29, 2010 IP
  8. gree124

    gree124 Well-Known Member

    Messages:
    721
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #8
    yes we are
     
    gree124, May 30, 2010 IP
  9. Flamingw0rm

    Flamingw0rm Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i think that will work
     
    Flamingw0rm, May 31, 2010 IP
  10. social-media

    social-media Member

    Messages:
    311
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    35
    #10
    If you want to force users to login before seeing any page on your site then you'll want to include code similar to the above on EVERY page of the site in case a user arrives on some other page of the site. But I think you want to modify the above code slightly.

    You'll likely want to get the original requested URL and store it in some sort of session variable before redirecting to the login page (or pass it to the login page in encoded form as a query string parameter on the URL when you redirect to the login). Once the user logs in then your login page can redirect the user to the page they originally requested using the session variable or query string parameter.
     
    social-media, Jun 1, 2010 IP