I am trying to make my code more clear using the include function of php. I am using the same part of code in three of my pages but the one of this pages is the same page that i call when I execute this part of the code. So can I instead of
action="<?=$_SERVER['PHP_SELF']?>"
to use the link of this page(action=”thispage.php”)? Also in order to use include the code has to be exactly the same? I mean I have parts of my code that are almost the same only some small things change. Such as in each page I have a css style that I apply in the selected link. Is there any way to change some things of the code included? Thank you!
Sure, you could. Although a much simpler way would be to use
action=""when it’s on a form. The empty string tells the browser to submit the form to the page you’re currently on.When you’re including a file, it is actually included into your code, so it “inherits” all of the variables inside the current scope. You can define a variable inside your file and then use that variable inside a conditional in the other file to determine what exactly it’s supposed to do.