0

I'm currently making a desktop application in html.

Now I want to get the username of the current user of the local system.

I do this in php:-

$wand = getenv("HOMEDRIVE").getenv("HOMEPATH")

but now I want to make this in html so it does need a server.

thanks.

2 Answers 2

1

JavaScript runs in the context of the current HTML document, so it won't be able to determine anything about a current user unless it's in the current page or you do AJAX calls to a server-side script to get more information.

JavaScript will not be able to determine your Windows user name.

To do using AJAX:

request = $.ajax({
        type: 'POST',
        url: 'form.php',
        data: { }});

        request.done( function(response) {
    alert (response)}
        })

});

On form.php Side:

<?php>
$wand = getenv("HOMEDRIVE").getenv("HOMEPATH")
echo $wand;
?>
Sign up to request clarification or add additional context in comments.

2 Comments

how to do this on ajax?
Make an AJAX request to the server, and get the username in response. Like, as you mention the way to do it in PHP
0

.php file

<h1><?php echo getenv("HOMEDRIVE").getenv("HOMEPATH"); ?></h1>

Or you can declare the variable first

<?php $wand = getenv("HOMEDRIVE").getenv("HOMEPATH"); ?>
<h1><?php echo $wand; ?></h1>

.html file You can use jquery ajax

<h1 id="username"></h1>
$( "#username" ).load( "/username.php" );

username.php

<?php echo getenv("HOMEDRIVE").getenv("HOMEPATH"); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.