Home > front end >  How to make <?php include_once('my_username_here.txt'); ?> with with <?php echo h
How to make <?php include_once('my_username_here.txt'); ?> with with <?php echo h

Time:10-17

On the welcome page after the user has signed in, if I add this line of code <?php include_once('my_username_here.txt'); ?> and I replace “my_username_here.txt” with “john.txt”, it pulls what is saved on john.txt and shows it on the welcome page.

When I add this line of code <?php echo htmlspecialchars($_SESSION["username"]); ?> into this line of code like this <?php include_once(<?php echo htmlspecialchars($_SESSION["username"]); ?>.txt'); ?> it does not work. I have looked high and low and tried different ways and noting seems to work.

CodePudding user response:

If I understand you correctly so all you need is to edit it like this

<?php 
   include_once(htmlspecialchars($_SESSION["username"]) . '.txt'); 
?>

or for simplification, you could edit it like this one

<?php 
   $file_name = htmlspecialchars($_SESSION["username"]) . '.txt';
   include_once($file_name); 
?>
  • Related