exist a hotspot with php?
No.
It sounds to me like you're misunderstanding how DNS works... a subdomain doesn't need to point to the same IP as the main domain.
Your hotspot login page can be located on the router, and let's say that it's the private IP 192.168.0.1. At the router, and the hotspot server profile in particular, you can adjust the hotspot to respond to the DNS name "example.com". You may have to also add the name and IP in "/ip dns", but still,
the point is you can make it so that when users type (or are redirected to) "http://example.com", they get the login page from 192.168.0.1.
At the same time, you can have your web server, and let's say that it's at the public IP 10.10.10.1. In the "/ip dns" menu, you can add "portal.example.com" (or whatever name you like that ends with ".example.com") and make it point to that IP. That way,
you're making it so that when users type (or are redirected to) "http://portal.example.com", they'll get content from 10.10.10.1.
And THAT is where it gets interesting... cookies do NOT care about the IP of the other end - they care of the domain name the other end is accessed with. So a cookie set by "example.com" is available to not only the server responding to "example.com" (i.e. the router), but they're also available to any server that responds to a domain name ending in ".example.com" (in this case, the server, responding to "portal.example.com".
my server has to be online or not?
Your server would have to always be online, yes. Just as your router. Without it, users can still login and access the internet, but they won't be able to access whatever you're trying to provide with PHP (and I'm only guessing you're making a way for them to edit their credentials and more, right?).