-7

Would be great with an opposite "exclude" from include,

Furious Mountain
  • 1,323
  • 3
  • 16
  • 44
  • `if (somethig is true) { include }` – u_mulder Nov 17 '16 at 09:06
  • 2
    Because you don't need it. You just don't include it. – Sami Kuhmonen Nov 17 '16 at 09:06
  • if you really really want to work this way, include the form in the `else` branch if your `if`. – cili Nov 17 '16 at 09:58
  • 1
    Please don't vandalize your posts. – Glorfindel Nov 17 '16 at 10:17
  • 2
    @Fille no - people have put effort in answering your question. Deleting your question would throw away their work as well. – Glorfindel Nov 17 '16 at 10:19
  • Please stop defacing this post. We're not going to delete it, and you are not allowed to deface it. That's not how the site works. – elixenide Nov 17 '16 at 16:21
  • Related: [how to exclude a file after including it in php?](https://stackoverflow.com/q/24436563/2943403), [PHP How to exclude a file which is included in the file I am including?](https://stackoverflow.com/q/62295281/2943403) , [Exclude a php include file if filename matches](https://stackoverflow.com/q/34313057/2943403) I also believe this question is rather unclear and poorly asked/presented (not a great fit for Stack Overflow and likely to confuse future researchers). – mickmackusa Aug 23 '22 at 22:07

3 Answers3

0

You can't exclude, because the include happened before. The code is already executed at the time, you want to exclude it.

Best way to solve this issue is include conditionally:

if (!$loggedin) {
  include "loginForm.php";
}
jenald
  • 132
  • 2
  • 8
  • 1
    i think you forgot a `!`, because currently you include the login form **only if** you are logged in – Franz Gleichmann Nov 17 '16 at 09:21
  • Of course it doesn't work, if you just copy & paste this code. You have to adapt it to your needs. I'm not your coding-assistant, I'm just trying to help – jenald Nov 17 '16 at 09:36
-1

Actually, you should do like this

1)Have some loginForm route like http://localhost:5000/login submit it for processing.

2) In that file set up the session and redirect to another route which will show you the newCartForm and logoutForm.

It is bad practice to show a form on the basis of one true or false condition.

PassionInfinite
  • 640
  • 4
  • 14
-1

You can try this:

// Hide Navbar and Sidebar if User = Student
if ($_SESSION["role_user"] != "Student") {
  include "modulos/navbar.php";
  include "modulos/sidebar.php";
}

So in this case, for all users will be showing navbar and sidebar, except for "Student" role user.

Reichlich
  • 314
  • 2
  • 7