View Full Version : java script only runs with ip address and not domain name

05-13-2011, 08:13 PM
I have an unusual problem that just started yesterday.

When visitors to my site go to the login page, to some the login boxes (e-mail address and password) don't show.


One of my computers in my office shows the script and some don't. So I know what my visitors mean when they say nothing shows up.

If we use the ip address, then the script runs all the time.

Any help would be greatly appreciated. Thanks.

05-13-2011, 08:23 PM
If you are using Ajax (as it looks like you are) then the Javascript same-domain* security policy applies. It appears you've hard-coded the ajax request using the IP, meaning accessing the page with the IP will work, any other access will not. Since the ajax routine is built in PHP you should probably make the ajax request dynamically use the host that was used to request the page. If the visitor is coming from the domain, use the domain to call the ajax, if the visitor is coming from the IP address, use the IP address to call the ajax.

*In Javascript you are not allowed to access resources via XHR (Ajax, etc.) from a domain/IP different than the one the page is called from. That is, www.theeagleextra.com != theeagleextra.com (without www) and != (or any subdomains or completely different domains or IPs).

05-13-2011, 08:40 PM

I purchased the member login software from a company that installed it on my ftp site for me.

It all worked up until just a couple of days ago. Why would it work for a few weeks and then not work? All the PHP files are still dated 3-20-11 -- the date they were uploaded.

After I read your post, I changed the hyper links to using the ip address. Is this what you meant?

05-13-2011, 10:13 PM
I don't know why it would work and then not work.

The code I am talking about is in http://www.theeagleextra.com/member/frontend/load_login.php:

MemberLogin.LoginSettings = {
URL: "",
uploadUrl: "",
installFolder: "/member/",

messagesWrapper: document.getElementById("ml_login_messages"),
contentWrapper: document.getElementById("ml_login_content"),

validationName: "Name",
validationEmail: "Email",
validationInvalidEmail: "Invalid email address",
validationPassword: "Password",
validationPhone: "Phone",
validationWeb: "Web",
validationLoginDataRequired: "Email and password are required."

MemberLogin.Ajax.get("", "ml_login_content");

That's coded in Javascript but the src to that script is a php file so it should be possible to modify the PHP file to call the current host and not the hardcoded IP address.

If you purchased this software you should probably contact the company for support.

05-13-2011, 10:30 PM

where did you get that fragment of code you posted? Is it something you and I can hack and make the changes ourselves?

The company I bought the software from offers only 12 hours of customer service every day. I think they're on their off hours, because I'm not hearing from them.

05-13-2011, 10:43 PM

I just thought of something, when I was building my site, I was using only my ip address. When I was finished, my hosting company that has my ftp transferred my domain name onto it. That's probably why it's configured for my ip address.

The computer I'm using right now shows the script perfectly, but other computers don't.

05-14-2011, 01:55 AM
That code fragment came from http://www.theeagleextra.com/member/frontend/load_login.php. You are calling that script (it is a javascript even though it's delivered via php) from within your page.

I don't know enough PHP to help with modifying that to dynamically use the same hostname as the calling page, though it should be simple/trivial to do if you want to ask in the PHP forum.

If you intend to only use the site via domain name now that it is set up, you could just modify the script to use the domain instead of the IP address and that should work.

I don't know how/why it is working for you on one computer - it seems like you might have custom browser settings that are bypassing javascript's same-domain policy.

Your best bet is still the company you purchased the script from, especially since they installed it. Ask them if they can re-configure it to work with your domain now that that is set up.

You should make an offline backup of all files on your site (download everything via FTP) before you/they make any modifications.