*

amare

  • **
  • 71
How to stop users who are not logged in
« on: March 25, 2014, 09:11:10 AM »
Hi guys I know using the code

{if $smarty.session.UserId != ''}

{/if}

Will hide objects from members who are not logged in but what I would like to do is know the code that will redirect them to the login page so for example when they hit the search button instead of showing them the search result it will ask them to log in or register also I would want to to do it so people and view profiles unless logged in

I'm guessing its a little code that would go in specific files but I don't know which ones either
Any pointers to start with
Osdate 2.6
php 5
not sure what MSQL

*

CBG

  • *****
  • 673
    • osDate Forum
Re: How to stop users who are not logged in
« Reply #1 on: March 25, 2014, 09:25:33 AM »
To redirect to the login page add the following in the .php file

Find
Code: [Select]
if ( !defined( 'SMARTY_DIR' ) ) {
     include_once( 'init.php' );
}

After Add
Code: [Select]
include('sessioninc.php');

So if you wanted to stop members not logged in, viewing profiles, you should put that code in showprofile.php
Regards,
CBG (Garry)
osDate: 2.6.5, 2.7 & Evo
PHP: 5.5.x/5.6.x (5.3.x to 5.6.x) | MySQL: 5.5.34-cll

*

CBG

  • *****
  • 673
    • osDate Forum
Re: How to stop users who are not logged in
« Reply #2 on: March 25, 2014, 09:29:52 AM »
Not tested this, in a template file you could try

Code: [Select]
{if $smarty.session.UserId != ''}
{include file="login.tpl"}
{else}
TEMPLATE CODE
{/if}
[/code}
Regards,
CBG (Garry)
osDate: 2.6.5, 2.7 & Evo
PHP: 5.5.x/5.6.x (5.3.x to 5.6.x) | MySQL: 5.5.34-cll

*

amare

  • **
  • 71
Re: How to stop users who are not logged in
« Reply #3 on: March 25, 2014, 01:58:15 PM »
A quick response thanks....
i had a play with that code over lunch putting it in several .TPL files to see if it would work but unfortunately it didn't, well at least i couldn't get it to work, i will be trying again and having a little play again tonight so hopefully i will get it done.

again thanks for the help

paul
Osdate 2.6
php 5
not sure what MSQL

*

amare

  • **
  • 71
Re: How to stop users who are not logged in
« Reply #4 on: March 25, 2014, 03:16:04 PM »
i couldn't stay away i should be working but i am hooked with playing with the code.......

i put the code in onlineuser.php, searchmatch.php and showprofile php and i have achieved what i was looking for thanks CBG (Gary) for your time in helping me get this done  :)
Osdate 2.6
php 5
not sure what MSQL

Re: How to stop users who are not logged in
« Reply #5 on: March 27, 2014, 05:48:36 PM »
could you please write where the could shall be added? I have the same problem.

*

CBG

  • *****
  • 673
    • osDate Forum
Re: How to stop users who are not logged in
« Reply #6 on: March 27, 2014, 06:43:28 PM »
See the second post.
Most if not all .php file has the find bit and when you want to make them login, you add the bit under after add.
Regards,
CBG (Garry)
osDate: 2.6.5, 2.7 & Evo
PHP: 5.5.x/5.6.x (5.3.x to 5.6.x) | MySQL: 5.5.34-cll

Re: How to stop users who are not logged in
« Reply #7 on: March 27, 2014, 07:35:51 PM »
Issue solved Thanks to CBG

The code should look like this:

if ( !defined( 'SMARTY_DIR' ) ) {
   include_once( 'init.php' );
   include('sessioninc.php');
}

Re: How to stop users who are not logged in
« Reply #8 on: April 03, 2014, 07:52:57 PM »
Issue solved Thanks to CBG

The code should look like this:

if ( !defined( 'SMARTY_DIR' ) ) {
   include_once( 'init.php' );
   include('sessioninc.php');
}
 

with this code i have blank page how can i redirect to login page

*

CBG

  • *****
  • 673
    • osDate Forum
Re: How to stop users who are not logged in
« Reply #9 on: April 03, 2014, 08:04:09 PM »
Try

Code: [Select]
if ( !defined( 'SMARTY_DIR' ) ) {
   include_once( 'init.php' );
}

   include('sessioninc.php');
Regards,
CBG (Garry)
osDate: 2.6.5, 2.7 & Evo
PHP: 5.5.x/5.6.x (5.3.x to 5.6.x) | MySQL: 5.5.34-cll

Re: How to stop users who are not logged in
« Reply #10 on: April 03, 2014, 08:10:16 PM »
Issue solved Thanks to CBG

The code should look like this:

if ( !defined( 'SMARTY_DIR' ) ) {
   include_once( 'init.php' );
   include('sessioninc.php');
}


 

with this code i have blank page how can i redirect to login page
code work only you see blank page it is beter if redirect to login page

*

CBG

  • *****
  • 673
    • osDate Forum
Re: How to stop users who are not logged in
« Reply #11 on: April 03, 2014, 11:13:38 PM »
It should redirect, what page are you trying this on?
Regards,
CBG (Garry)
osDate: 2.6.5, 2.7 & Evo
PHP: 5.5.x/5.6.x (5.3.x to 5.6.x) | MySQL: 5.5.34-cll

Re: How to stop users who are not logged in
« Reply #12 on: April 03, 2014, 11:22:38 PM »
It should redirect, what page are you trying this on?

ok it works problem was that i have edit showprofile.php

Re: How to stop users who are not logged in
« Reply #13 on: July 15, 2014, 02:20:13 AM »
Try

Code: [Select]
if ( !defined( 'SMARTY_DIR' ) ) {
   include_once( 'init.php' );
}

   include('sessioninc.php');

This work for me too.

Thanks.