My first question

Discussing Html . Code , Software , other

Moderators: egami, macek, gesf

Post Reply
kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Thu Oct 08, 2015 3:43 am

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

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Thu Oct 08, 2015 4:44 pm

Hi Kris,

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

Code: Select all

<script language="Javascript" src="http://x.x.x.x:81/phptest.php?Name=<?php echo $bruk;?>"></script>
Hope that helps,
Jon

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Sun Oct 11, 2015 5:19 am

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

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Sun Oct 11, 2015 7:48 am

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: Select all

var_dump($bruk);
var_dump(getenv('USERNAME'));
var_dump(getenv('USER'));
Hope that helps,
Jon

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Sun Oct 11, 2015 12:23 pm

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

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Mon Oct 12, 2015 3:59 am

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/3899 ... th-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?

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Wed Oct 14, 2015 5:25 am

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

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Wed Oct 14, 2015 11:18 am

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

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Wed Oct 14, 2015 1:38 pm

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

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Fri Oct 16, 2015 2:45 am

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

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Sat Oct 17, 2015 7:28 am

Did you check out the link:
http://stackoverflow.com/questions/3899 ... th-php-iis
I think that answers your question.

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Sun Oct 18, 2015 4:24 am

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

element121
php-forum Fan User
php-forum Fan User
Posts: 628
Joined: Sat Jun 06, 2015 11:46 am
Contact:

Mon Oct 19, 2015 1:00 pm

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

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Tue Oct 20, 2015 4:45 am

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

kristoffer
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Oct 08, 2015 3:27 am

Fri Oct 23, 2015 9:15 am

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

Brgds kris.

Post Reply