+ 1

what are the best ways to show different navbar based on if the user logged or not?

Hello 😊 I want to know what are the best ways to show different navbar based on if the user logged or not? like one way is to make two navbar in the html file and use css to make one display block and the other display none and switch between them using js. or another way is to use php "if statement"... What other ways there are ? and I know there is a lot of ways but what the easest way, also clean code. Thank you all :).

28th Aug 2018, 8:34 AM
Zaid A Hasan
Zaid A Hasan - avatar
13 ответов
+ 2
$myusername = mysqli_real_escape_string($db,$_POST['username']); $mypassword = mysqli_real_escape_string($db,$_POST['password']); $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'"; $result = mysqli_query($db,$sql); $row = mysqli_fetch_array($result,MYSQLI_ASSOC); $active = $row['active']; $count = mysqli_num_rows($result); if($count == 1) { session_register("myusername"); $_SESSION['login_user'] = $myusername; echo "<div id =' login navbar'></div>"; }else { die(" Error 504"); } //HOPE IT HELPS
28th Aug 2018, 12:19 PM
Femi
Femi - avatar
+ 3
Abbeymaniak Paul Nope But I advise you validate your form both client-side(js) and backend(php).
19th Sep 2018, 10:34 PM
Femi
Femi - avatar
+ 2
if(mail($to, $subject, $message, $headers)){ echo "<script>alert("Sent Successfully");</script>"; header("Location: index.php"); } else { /* Instead of using a function you can use die to handle errors */ die("Error"); } #Abbeymaniak Paul
19th Sep 2018, 10:29 PM
Femi
Femi - avatar
+ 1
If you use js, your server have to send more data (logged and not logged content) more js for handling they, client can "see" something of logged behaviours but all its a client work... Other side, your server have to "displatch" right page for your client then you get less data sendend and client have to do less work (but server a few much)... I would like second choice
28th Aug 2018, 8:52 AM
KrOW
KrOW - avatar
+ 1
bros ishola please how can I get in touch with you? I'm a total novice and wanna get my website on d web.. please I need help
29th Aug 2018, 10:14 AM
Abbeymaniak Paul
Abbeymaniak Paul - avatar
+ 1
thanks a lot bro, I have been expecting ur reply sir, I'm a strong follower. please do I have to deactivate any jquery handling form validation?
19th Sep 2018, 10:32 PM
Abbeymaniak Paul
Abbeymaniak Paul - avatar
+ 1
God bless you for the reply bro, you be baba oooo, I dont mind learning from you sir #ishola Obafemi
19th Sep 2018, 10:34 PM
Abbeymaniak Paul
Abbeymaniak Paul - avatar
0
Thank you KrOW and Ishola Obafemi I'm Front-End dev. and I'm just starting so my knowledge not that good but not bad also. I know that JS is not the best way and that's why I'm asking. I want to Know what ways there are. anyway thank you both you was very helpful 😊.
31st Aug 2018, 11:47 AM
Zaid A Hasan
Zaid A Hasan - avatar
0
Abbeymaniak Paul what do you need ? mabey I can help you 😊
31st Aug 2018, 11:49 AM
Zaid A Hasan
Zaid A Hasan - avatar
0
still on my contact form, how can I redirect after form submission to the index.php with an alert message of sent successfully! although I'm not using a phpmailer
19th Sep 2018, 10:24 PM
Abbeymaniak Paul
Abbeymaniak Paul - avatar
0
this is the part I'm having issues: if(mail($to, $subject, $message, $headers)){ header("Location: index.php"); } else { function died ($error){ echo $error; }
19th Sep 2018, 10:25 PM
Abbeymaniak Paul
Abbeymaniak Paul - avatar
0
the email do get sent and redirected to index.php but I wan. a message indication message sent
19th Sep 2018, 10:25 PM
Abbeymaniak Paul
Abbeymaniak Paul - avatar
0
OK boss I'll work on that and get back to you, thanks a lot omo iyami #ishola Obafemi
19th Sep 2018, 10:40 PM
Abbeymaniak Paul
Abbeymaniak Paul - avatar