My first question

A

Anonymous

Guest
Hi.
I am a newbe and have a (possible stupid) question : :(

How to use an variable when calling a php-script ?
Something like this :

<?php
$bruk = getenv('USERNAME') ?: getenv('USER');
?>

<script language="Javascript" src="http://x.x.x.x:81/phptest.php?Name=$bruk"></script></p>

Is it possible to do this or somthing like this ?

Brgds Kris
 
Hi Kris,

To output PHP variables in HTML you will need to echo them out:

Code:
<script language="Javascript" src="http://x.x.x.x:81/phptest.php?Name=<?php echo $bruk;?>"></script>

Hope that helps,
Jon
 
Thx Jon.
I am sorry to say that I can't get this to work.

Is the syntax correct or do I miss the variable ?

I'm not sure this i s working :
<?php
$bruk = getenv('USERNAME') ?: getenv('USER');
?>

How to get an value into $bruk ?

Brgds Kristoffer
 
Hi Kristoffer,

What are you trying to accomplish with the USER / USERNAME?

Where is that data coming from, are you setting it with putenv()?

Use var_dump() to debug your code and see what's in those variables:

Code:
var_dump($bruk);
var_dump(getenv('USERNAME'));
var_dump(getenv('USER'));

Hope that helps,
Jon
 
Hi .
I am trying to fetch the environment USERNAME and to put it into an SQL-database called LOG.
This is for logging all the Clicks in my Intranet.
If I put the code in the php-file at the server I only fetch the local user at the server (administrator).
I want to get the lokal username.

I have tought about using cookies but i tought this was an easyer way to do it.

I want to send the username (incl time and date) of the person that did the click, not the adminuser at the server, to the SQL.
Therefor i tried to do something like this :
<script language="Javascript" src="http://x.x.x.x:81/phptest.php?Name=$bruk"></script></p>
where Name is the name of the user (fetched from env USERNAME, AD-user or maybe a cookie).

I tryed to check var_dump, but locally i got nothing, but at the server php I only got the administrator.

Brgds Kristoffer
 
How is the local user authenticating on the network?
Assuming it's windows authentication, then have a look at this post:
http://stackoverflow.com/questions/3899643/how-to-read-windows-loged-in-username-with-php-iis

Really without knowing how your internal network is set-up, it's difficult to know.

If you aren't using Windows authentication, then the user is logging in through a web interface?
 
All users are login into AD where I set up an environment called USER=<loginname> (=firstname).
Therfor I thought I could use this code to get the firstname/loginname :

<?php
$bruker="John Doe" //default if it's not abel to get the environment
$bruker = getenv('USERNAME') ?: getenv('USER');
echo "My first PHP script!";
?>

And then I put it into the SQL using this code :
<script language="Javascript" src="http://x.x.x.x:81/phptest.php?Name=" . $bruker></script>

This code is working but then all will have the same name:
<script language="Javascript" src="http://x.x.x.x:81/phptest.php?bruker=Kris">

But I am not sure the PHP code is working at all inside the html.
Maybe I need something in some config- or/ini-files ?
But the phptest.php is working ok.

Thank you for your help.
Kris
 
Hello everybody.
I'm trying to use a few PHP-lines inside an HTML-file (index.html)
Something like this :

<html>
<body>
<?php
$bruk ="KT";
echo "My first PHP script!";
?>
</body>
</html>

But nothing happens ???

All the html code is working fine.

How can I make this to work ?
Or at least tell me what i'm doing wrong

Please :help:

Brgds Kris
 
For the PHP to run, you need to change the filename to index.php
 
Thx

( I feel ia bit stupud)

Almost everything is working except the USER problem.
I want to use local user an not the admin user at the server.

This line fetches the adminuser at the server and not the local user :
$bruker = getenv('USERNAME') ?: getenv('USER');

Any tips would be appriciated.

Brgds kris
 
Hi.
I am running a network with a domain Controller, Apache, PHP and Mysql. But no IIS.
Everything is working fine except these :

$_SERVER['LOGON_USER'];
$_SERVER['AUTH_USER'] ;
$_SERVER['REDIRECT_LOGON_USER'];
$_SERVER['REDIRECT_AUTH_USER'];

I have managed to get the local IP, but not the login_name / username.

Maybe it's possible to create an cookie in Windows 2008 R2 login script ?

Brgds Kris
 
The authenticated user you get with Windows Authentication on IIS, not sure you will be able to get that with Apache.
 
Ok, thanks anyway.

I am still not able to read the local environment so therefor i will try to use Cookies.
I'm able to make, read and delete cookies, but i have problem making a little logon window.

Mayby somone can tell me how to . . .

I want to do this:
1 : chech if there exists an cookie called userabc
2 : Get the name from the cookie and use this name for loggin i an SQL db.
3 : If the cookie dont exists ask for username
4 : save the cookie calles userabc containing the username.

It is "ask for username" i have problems to do.

Thanks
Kris
 
Hi.
Anybody who knows how to make an popup-windows asking for username ?

Brgds kris.
 
Back
Top