Hello.
I have a quick question regarding php code layout and also variables.
Does it make any difference whatsoever if I choose to lay out my code in sections like this? Note that this is just some example random code.
<?php
session_start();
if (isset($_SESSION['username'])) {
$username = htmlspecialchars($_SESSION['username']);
}
?>
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php';
some code here etc
?>
<?php
echo '$username';
?>
Do the php tags after the first set make no difference at all, and are purely an aesthetic choice to clump together certain parts of the code if I chose to do so?
Would the connection.php still be ‘set’ in the later php tag sets or would I have to call it for each? Somehow, I doubt that.
Also, regarding variables. If I use, like in the above example, htmlspecialchars on the $username variable… whenever I use the $username variable later in my code, I can just use it as $username, and not have to ‘re-do’ htmlspecialchars, correct? Once it is set, it is set until I change it in that particular page. Even if it were done like this:
<?php
session_start();
if (isset($_SESSION['username'])) {
$username = htmlspecialchars($_SESSION['username']);
}
?>
<?php
include hiuser.php
?>
<?php // this is hiuser.php
echo '$username';
?>
Thank you for your input, php masters of sitepoint.