How do I set a variable equal to the current user's username?
P粉914731066
P粉914731066 2024-01-16 21:37:21
0
1
292

As mentioned in the question above, I'm trying to set a variable in my javascript as the value of the user's username. This is how my code is set up:

function submitApproveModal(){ 
  this_file = currentFile;
  
  var approvers = "";
  if(document.getElementById('approvers').checked){
    approvers = '<?php $_SESSION['username'] ?>';
  }
  
  approveFileAjax(this_file.uid, approvers);
}

I know this is not how it works and was wondering how I could rewrite my code so that the approver equals the user's username?

P粉914731066
P粉914731066

reply all(1)
P粉996763314

You just forgot about "echo":

approvers = '<?= json_encode($_SESSION['username']) ?>';

But as mentioned before, mixing Javascript and PHP is a bad idea.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!