In general, I make a script and I need to do to

  • for guest [group=0]Войти | Регистрация[/group] [group=0]Войти | Регистрация[/group] ,
  • for user [group=1]Выйти[/group] .

If you do a conditional statement:

 if($_SESSION['session_id'] = '') {echo 'Вход';} else {echo 'Выход';} 

then it is inconvenient ... Here you need to do, as I said above (with DLE I could not cut it). All scripts in the sessions. (This is not DLE, but samopis.)

Closed due to the fact that the essence of the question is not clear to the participants Visman , Vladimir Glinskikh , Regent , Aries , aleksandr barakin 24 Oct '15 at 7:37 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And what's uncomfortable? usually at the beginning of the script they do authorization checks, and then <pre> if ($ userID> 0) {?> Log Out <? } else {?> Log In <? } </ pre> As an option - the operator ?: <pre> echo ($ userID> 0)? 'Log Out': 'Log In'; </ pre> - Sh4dow pm
  • you need [group = 0 ~ 1] - Makar
  • imkho, fasten bydlokodit and pass to shablonizator and mvc! - kemerov4anin
  • The man does not know the elementary. As if having a block with a template engine is much more difficult) - Sh4dow

3 answers 3

This can be done in javascript, unfortunately, I don’t have the code, but it’s done like this:

On JS we do:

 function checkUL() { var elem = document.getElementById('touser'); если (пуста кука) { elem.innerHTML = '[group=0]Войти | Регистрация[/group]'; } else { elem.innerHTML = '[group=1]Выйти[/group]'; } } <body onload="checkUL"> <label id="touser"></label> </body> 

Add your own tags.

  • No, not that! in [group = 0 ~ 1] there can be anything you like! [/ group] you need via php - Makar

I have always been in favor of reducing the load and speeding up the work, so I suggested it to JS. How do you like that?

 <?php function logginedOrNot() { switch (empty($_SESSION['session_id'])) : case true : $answ = 'no'; break; case flase : $answ = 'yes'; break; endswitch; return($answ); } ?> 
  • Damn, I do not see here [group = *] - Makar
  • What are you doing?)) Is it written <pre> function logginedOrNot () {return (! Empty ($ _ SESSION ['session_id']))? 'Yes': 'no';} </ pre> With the switch it will naturally be weighting. Makar, and you tell me, where in general to take what is in the "group ="? Where does this value come from? - Sh4dow
 $tpl['group0'] = '[group=0]...[/group]'; $tpl['group1'] = '[group=1]...[/group]'; if($_SESSION['session_id'] = '') { echo $tpl['group0']; } else { echo $tpl['group1']; } 

IMHO, it is more convenient to store the pieces of the template in variables, since all of them are located in the same place in the code.