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.

Session

Discussion in 'PHP' started by baris22, Jul 7, 2009.

  1. #1
    Hi everybody,

    I am learning php and I need some help.

    I want to hide some text from users who are not logged in. I do this

    
    $fullpage = preg_replace("#http://rapidshare.com/(.+?)\ #i", "File is on rapidshare.com! <br />", $fullpage);
    
    PHP:
    Now, How can i not hide this text if user is logged in. I managed to make a loggin script.

    
    
    <? 
    session_start();
    if(!session_is_registered(myusername)){
    header("location:main_login.php");
    }
    ?>
    
    
    PHP:
    I think i need to use if statement but i do not know how to.

    Thanks
     
    baris22, Jul 7, 2009 IP
  2. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Start using

     
    if (isset($_SESSION['sessionname']))
    {
    stuff you want only logged in people to see....
    }
    else
    {
    echo "You must be logged in to see this content";
    }
    
    PHP:
    session_is_registered is getting deprecated in the next version of PHP. Start updating your code now.
     
    SHOwnsYou, Jul 7, 2009 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Assuming that you are setting the myusername session variable, you would want to do this.

    
    session_start();
    if(!$_SESSION['myusername']){
    header("location:main_login.php");
    }
    
    PHP:
     
    jestep, Jul 7, 2009 IP
  4. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    thank you all.

    it worked

    
    <?
    if (isset($_SESSION['myusername']))
    {
    ?>
    <?= stripslashes ($full)?>
    <?
    }
    else
    {
    ?>
    <?= stripslashes ($fullpage)?>
    <?
    }
    
    ?>
    
    PHP:
    How can i tidy up this code?

    thanks
     
    baris22, Jul 7, 2009 IP
  5. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?
    if (isset($_SESSION['myusername']))
    {
    ?>
    echo stripslashes($full);
    }
    else
    {
    echo stripslashes($fullpage);
    }
    ?>
    
    PHP:
     
    SHOwnsYou, Jul 7, 2009 IP