hello all. i am writing a php / mysql script that does various things, but in addition to those things i need it to get the username of whoever is using the front end. any help is greatly appreciated! also i can post some code snippets if you want a feel for what im doing.

Do you mean you need the user to submit their name?

If so you could just use and HTML form and post it to your php page for processing.

no. everyone in my office (like 9 people total) has a Unix username they have to use to log into our company website. the website has stuff like a calendar of events, technical info, various forms for things, and it will have the IP database front end i am writing for it. when a user uses this new front end i want it to get his or her username because it will go into a row in the IP table (telling other users who inserted that row of data). does that clear it up a little bit? thanksa.

You could possibly store the username in the session variable after a successful login and then insert that value in the table.

ok. they will only be using my front end if they've logged in successfully, so we can assume that all logins were successful. how would i go about doing that? thanks!!

Post (method="post") the html control data e.g. txtusername, txtpassword to your php page. Then on your php page you need to start_session() (or something like that) and then assign a value to the session variable e.g. $_SESSION = $_POST[txtusername].

Now you can access that variable while the session is live.

e.g.

<?php
    echo $_SESSION['varUserName'] //output user name
?>

My php is a bit rusty so it might not be exact.

ok i think i understand the second part of what you said. but how do i post the php control data (txtusername, txtpassword) to my php page? i really am new to php and appreciate all the help.

It's not too difficult. Say you had a login page with two text areas (username and password) and a button (submit) you would use an HTML form like this...

<form method="post" action="authenticate.php">
username
<input type="text" name="txtusername">
password:
<input type="password" name="txtpassword">
<input type="submit" value="submit" name="btnsubmit">
</form>

When you click submit the text box input is sent to authenticate.php.

i really dont wanna do that because when the user is using my IP database front end they will already have logged in to the server (//gothics). im asking how i can get that information that they've already given the server so i can identify who is making what modifications to the IP database. is there a way to do that? sorry if im being a pain.

There might be another way but i only know the method that i've explained above.

ok. some of what you said was helpful.....so thanks dude/dudette!

If they have already logged in to some other page before getting to your front end, the user info may already be in the session. Can you ask the developers of the other system about that? They can probably pass any session info you need via the link to your page.

You could probably use cookies?

The user logs in once, then a cookie containing his/her username is stored in the computer. When the user enters info into a row, with php code you get the username from the cookie and you can store it into your database. $user = $_COOKIE["name_of_the_cookie"];

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.