Node.JS & ExpressJS / Make a difference between Host Name and IP Address

I am logging to an express sesssion in two ways

  1. http://myhostname.com/login
  2. http://123.123.43.12/login

Ip adress of myhostname.com is 123.123.43.12.

To check if someone is already logging, I basically do for this example

if (user === req.session.username && pwd === req.session.password)

Then I make the same AJAX inquiry from a page

  1. In http://myhostname.com/main.html , AJAX inquiry to http://123.123.43.12/ajax => Error not logging
  2. In http://123.123.43.12/main.html, AJAX inquiry to http://123.123.43.12/ajax => Success

How can I tell expressJS (session) or node that myhostname.com and 123.123.43.12 are identical ?

You should check same origin policy. The rules for deciding if two urls are of same origin are strictly same protocol, host and port. myhostname.com and 123.123.43.12 are not of same origin by that.

AJAX follows same origin policy so it cannot inquiry any other page than its origin. Which is why if you access main from 123.123.43.12, you can access its ajax, but not from myhostname.com. If you use myhostname.com stick to it, or if you use 123.123.43.12 then stick to that. Don't use both interchangeably.