Jump to content

get user id of user using web php page


mikeweb

Recommended Posts

You will either have to pass it on thru hidden form variables or you can use session or cookies.

Personally I have used sessions. To use sessions you would have to start EVERY one of your pages with
[code]session_start();[/code]

then you would assign the session value
[code]$_SESSION['user'] = $_POST['username'];[/code]

once that is assigned you can call on the username at anytime by calling
[code]$_SESSION['user'][/code]

Ray
Link to comment
Share on other sites

Thanks Cratgo :-)

I tried that (novice user). but got the follow message...

===============
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at E:\Techassist\RMA\sendForm.php:6) in E:\Techassist\RMA\sendForm.php on line 141

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at E:\Techassist\RMA\sendForm.php:6) in E:\Techassist\RMA\sendForm.php on line 141
===============

Where is the best place to put this function ? (please excuse my ignorance, i'm new to php)


[quote author=craygo link=topic=105378.msg420878#msg420878 date=1156357124]
You will either have to pass it on thru hidden form variables or you can use session or cookies.

Personally I have used sessions. To use sessions you would have to start EVERY one of your pages with
[code]session_start();[/code]

then you would assign the session value
[code]$_SESSION['user'] = $_POST['username'];[/code]

once that is assigned you can call on the username at anytime by calling
[code]$_SESSION['user'][/code]

Ray
[/quote]
Link to comment
Share on other sites

Here's my code... still has empty field for username:
what am i doing wrong ?

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
//to obtain user id
session_start();

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php

function sendForm()
{

//ob_start();

$_SESSION['user'] = $_POST['username'];

$formData='

<table width="400" border="1" cellspacing="1" bordercolor="#D40139">
  <tr>
    <td>
User: <input name="txtUser" type="text" value="'.$_SESSION['user'].'" readonly="true">
</td>
</tr>
</table>
';

//Send the completed form
sendForm();
?>
<body>
</body>
</html>

[/code]
Link to comment
Share on other sites

no not formally logging onto the site. but logging onto domain
I was hoping to grab the windows user id even from local environment vars.
Seems like such a task but definately valuable on my form.

Thanks for all the responses so far :-)


[quote author=rallokkcaz link=topic=105378.msg420920#msg420920 date=1156360516]
first of all are you even logged in?
second can you login through the login.php(.html .htm ext.)

that might help the problem
[/quote]
Link to comment
Share on other sites

here is some working code. You could eventually change the username form field to a dropdown menu later. But anyway

[code]<?php
session_start();
header("Cache-Control: private");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
//ob_start();

$_SESSION['user'] = $_POST['username'];
echo $_SESSION['user'];
} else {
?>
<form name=form action="<?=$_SERVER['PHP_SELF']?>" method=POST>
<table width="400" border="1" cellspacing="1" bordercolor="#D40139">
  <tr>
    <td>
User: <input name="username" type="text" value="">
</td>
    <td>
<input name="submit" type="submit" value="Submit">
</td>
</tr>
</table>
</form>
<?
}
?>
<body>
</body>
</html>[/code]
Link to comment
Share on other sites

Thank you

Tried the below as well ... still an empty username field.
But the below code looked promising... is there something else I need to do for it to work ?

Also tried the other suggestions by other members... you're all brilliant thanks again for the replies :-)

Mike

[quote author=Barand link=topic=105378.msg420967#msg420967 date=1156362997]
[code]
echo $_SERVER['LOGON_USER'];    // --> domain\username
[/code]

If you are using IIS you will have to disable anonymous logins, either at wwwroot level for the site or for the folder your app is in.
[/quote]
Link to comment
Share on other sites

Here the full code... all works fine except for that username field...
isn't it always the last part of the project that seems to be the hardest ?...lol

[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
//to obtain user id
session_start();

?>
<html>
<head>
<title>Corporate RMA Request Form - Submit Form</title>

<?php

function sendForm()
{
//ob_start();

$_SESSION['user'] = $_SERVER['LOGON_USER'];    // --> domain\username

//form vars
$newLine = "<br>";

//populate vars from post

$txtDate = $_POST["txtDate"];
$txtAgentName=$_POST["txtAgentName"];
$txtBanNum=$_POST["txtBanNum"];
$txtWirelessNum=$_POST["txtWirelessNum"];
$txtCustomerName=$_POST["txtCustomerName"];
$txtTicketNum=$_POST["txtTicketNum"];
$txtContactName=$_POST["txtContactName"];
$txtContactPhone=$_POST["txtContactPhone"];
$txtContactEmail=$_POST["txtContactEmail"];
$drpWirelessDevice=$_POST["drpWirelessDevice"];
$txtPinNum=$_POST["txtPinNum"];
$txtIMEI=$_POST["txtIMEI"];
$txtSimNum=$_POST["txtSimNum"];
$txtDefectNote=$_POST["txtDefectNote"];
$txtShipAttentionTo=$_POST["txtShipAttentionTo"];
$txtShipCompanyName=$_POST["txtShipCompanyName"];
$txtShipAddress=$_POST["txtShipAddress"];
$txtShipCity=$_POST["txtShipCity"];
$txtShipProv=$_POST["txtShipProv"];
$txtShipPostal=$_POST["txtShipPostal"];


$formData='

<table width="200" border="1" cellspacing="1" bordercolor="#D40139">
    <tr>
<td width=300 valign=top bgcolor="#D40139" align="right">
<b><span style="font-size:9.0pt;color:white">Corporate RMA</span></b>
</td>
<td width=300 valign=top bgcolor="#D40139" align="left"><b><span style="font-size:9.0pt;color:white">Request form</span>
</td>
    </tr>
  <tr>
    <td>
<div align="right">
Date: <br>
RMA #: <br>
User: <br>
</div>
</td>
<td>
<input name="txtDate" type="text" value="'.$txtDate.'" readonly="true"><br>
<input name="txtShowTicketNum" type="text" value="'.$txtTicketNum.'" readonly="true"><br>
<input name="txtUser" type="text" value="'.$_SESSION['user'].'" readonly="true">
</td>
</tr>
    <tr>
<td width=300 valign=top bgcolor="#D40139">
<b><span style="font-size:9.0pt;color:white">Customer Information</span></b>
</td>
<td width=300 valign=top bgcolor="#D40139">&nbsp;
</td>
    </tr>
  <tr>
    <td>
<div align="right">
Ban: <br>
Wireless #: <br>
Customer Name: <br>
</div>
</td>
<td>
<input name="txtBanNum" type="text" value="'.$txtBanNum.'" readonly="true"><br>
<input name="txtWirelessNum" type="text" value="'.$txtWirelessNum.'" readonly="true"><br>
<input name="txtCustomerName" type="text" value="'.$txtCustomerName.'" readonly="true">
</td>
</tr>
    <tr>
<td width=300 valign=top bgcolor="#D40139">
<b><span style="font-size:9.0pt;color:white">Contact Information</span></b>
</td>
<td width=300 valign=top bgcolor="#D40139">&nbsp;
</td>
    </tr>
  <tr>
    <td>
<div align="right">
Contact Name: <br>
Contact Phone: <br>
Contact Email:
</div>
</td>
<td>
<input name="txtContactName" type="text" value="'.$txtContactName.'" readonly="true"><br>
<input name="txtContactPhone" type="text" value="'.$txtContactPhone.'" readonly="true"><br>
<input name="txtCustomerName" type="text" value="'.$txtContactEmail.'" readonly="true">
</td>
  </tr>
    <tr>
<td width=300 valign=top bgcolor="#D40139">
<b><span style="font-size:9.0pt;color:white">Device Information</span></b>
</td>
<td width=300 valign=top bgcolor="#D40139">&nbsp;
</td>
    </tr>
  <tr>
    <td>
<div align="right">
Pin: <br>
IMEI: <br>
Sim Card #:
</div>
</td>
<td>
<input name="txtPinNum" type="text" value="'.$txtPinNum.'" readonly="true"><br>
<input name="txtIMEI" type="text" value="'.$txtIMEI.'" readonly="true"><br>
<input name="txtSimNum" type="text" value="'.$txtSimNum.'" readonly="true">
</td>
  </tr>
    <tr>
<td width=300 valign=top bgcolor="#D40139">
<b><span style="font-size:9.0pt;color:white">Shipping Information</span></b>
</td>
<td width=300 valign=top bgcolor="#D40139">
<b><span style="font-size:9.0pt;color:white">Defect Information</span></b>
</td>
    </tr>
  <tr>
    <td>
<textarea name="txtAddressFull" cols="35" rows="6" readonly="true">'.$txtShipAttentionTo.'
'.$txtShipCompanyName.'
'.$txtShipAddress.'
'.$txtShipCity.' '.$txtShipProv.' '.$txtShipPostal.'
</textarea>
</td>
    <td>
<textarea name="txtDefectNote" cols="35" rows="6" readonly="true">'.$txtDefectNote.'</textarea>
</td>
  </tr>
</table>
';

//populate email vars
echo $newLine;
$to = "michael.webster@rci.rogers.com";
//$headers = "From: michael.webster@rci.rogers.com";
$headers = "From: michael.webster@rci.rogers.com\r\nContent-type: text/html\r\n";
$subject = "Corporate RMAA request form - ".$txtTicketNum;
$body=$formData;

echo "To: ".$to.$newLine;
echo "From: ".$headers.$newLine;
echo "Subject: ".$subject.$newLine.$newLine;
echo "Body: ".$newLine.$body.$newLine;

if (mail($to, $subject, $body, $headers)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}


}//function end


//Send the completed form
sendForm();
?>
[/code]
Link to comment
Share on other sites

I will check with network admin about the settings mentioned.

Can i get the username from environment variables instead ?
They are set locally and may be ideal for what i'm trying to do.

Thanks

[quote author=Barand link=topic=105378.msg420983#msg420983 date=1156364319]
Did you check if your anonymous access was off?

"Directory Security" tab in website properties in IIS control panel

It should work- I use it regularly for controlling access. and getting email address from active directory


PS And make sure Intgrated Windows authenrication is ON
[/quote]
Link to comment
Share on other sites

Haven't tried ENV variables. I can have a try but not till next Monday when I'll be back in the office and on the network.

There are $_ENV['USERDOMAIN'] and $_ENV['USERNAME'] but I'm currently on my own PC running server and client on 1 PC so I don't know what values will be on a network server.
Link to comment
Share on other sites

Those were the first commands i tried on this journey but the page kept returning blank as i was accessing the server's env vars. Surely there's got to be a way of doing this aside from having my users log onto the web page with their long user ids. ultimately that would help me setup the proper email "sent from" when using mail().

Thanks for all your efforts. I've learnt alot from this site and all of you. :-)

[quote author=Barand link=topic=105378.msg421005#msg421005 date=1156366006]
Haven't tried ENV variables. I can have a try but not till next Monday when I'll be back in the office and on the network.

There are $_ENV['USERDOMAIN'] and $_ENV['USERNAME'] but I'm currently on my own PC running server and client on 1 PC so I don't know what values will be on a network server.
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.