-1

I m new to php, but i know basics. still i m learning in php.

In between gap, May i know, Is there possible to get unique id for differentiate from computer to another by using php?

Any suggestions would be highly appreciated.

Thanks.

pcs
  • 1,868
  • 4
  • 21
  • 48
  • Didn't get you. What you mean to say can you please elaborate – Narendrasingh Sisodia Aug 01 '15 at 06:41
  • Take a look - http://stackoverflow.com/questions/1420381/how-can-i-get-the-mac-and-the-ip-address-of-a-connected-client-in-php – Sougata Bose Aug 01 '15 at 06:42
  • Are you using PHP as a command line interface or as a web server script? – Ed Heal Aug 01 '15 at 06:57
  • Then you cannot. You are asking the client to give you information. They are at liberty to withhold that information. The best you can do is use cookies and hope that they accept them and are reasonable with them. – Ed Heal Aug 01 '15 at 06:59
  • @EdHeal: sorry my answer is incorrect..I need to know without using server machine.. – pcs Aug 01 '15 at 07:30
  • Do you want the unique identifier where the script is running or where it is serving information to? – Ed Heal Aug 01 '15 at 07:31
  • @EdHeal: sir, this is my question: Is possible to make LAN Messenger for multi platforms based on TCP/IP(UDP), by using php? thanks – – pcs Aug 01 '15 at 08:14
  • Why do you need to know the unique id for the computer - surely using a long poll for people that are connected will suffice – Ed Heal Aug 01 '15 at 08:17
  • I can't understand what you are said.. please explain me .. thanks – pcs Aug 01 '15 at 08:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84870/discussion-between-saina-and-ed-heal). – pcs Aug 01 '15 at 08:24
  • People that are interested connect to your server. Login using username/password. They get a session. use AJAX to request further messages. The server responds when a message occurs or times out. The client then asks again., – Ed Heal Aug 01 '15 at 08:25

2 Answers2

2

A computer doesn't have a permanent unique id that can be read by php.

So depending on your requirement you can try IP address, but this is likely to change over time. So only for a short period of time you can use this information.

If you want to know for a longer period of time, when the user comes back to your page, the best way to do this is by assigning your own unique id in a cookie to the browser. This cookie will remember which computer is which.

OSDM
  • 255
  • 1
  • 2
  • 10
1

You can set cookie to detect computer and also can detect IP. Now a days most of the ISPs uses dynamic IP address. Dynamic IP changes when client disconnect and reconnect internet connection. So cookie is the best way to detect a computer.

To set cookie use: setcookie('cookiename','cookievalue',time()+3600,'/','.example.com',0,1);

To retrive cookievalue: $_COOKIE['cookiename'];

To get IP: $_SERVER['REMOTE_ADDR'];

Neel Ion
  • 1,547
  • 1
  • 10
  • 14
  • actually i need to know.. for example, if i detect your computer mac address then i will send you a msg ..so my question is, it is possible in php? – pcs Aug 01 '15 at 07:03
  • If you want to detect users mac address you have to install application in users computer. If that application sends mac address then PHP will be able to detect mac address otherwise not. – Neel Ion Aug 01 '15 at 07:08
  • lon: we are using ipmessage app right?.. so by using php,,it is possible?.. and you are all said.. the computer's ip address will be changing.. if that, how it is possible, we are using ipmessage app..?. – pcs Aug 01 '15 at 07:11
  • Is possible to make LAN Messenger for multi platforms based on TCP/IP(UDP), by using php? thanks – pcs Aug 01 '15 at 07:24