I have two websites, web 1 is my news system and web2 handles payments for access to web 1.
I am not very good with the javascript, and seek some feedback on what i have done as i get an error self.opener.document is null or not an object and i have tried several things to try but run ouf option so i posteing it here to see if someone has an idea on what i doing worong or what i try to do is not possible.
So on my news site I call it web 1, a user click on an article, the user is taken to a webapge were it is asking to login, i created a script mixing php and javascript.
The user will intially be asked to click a link to validate the subscription. Web 2, will send a request back to the same page, but the header information would say what ip and useragent, it should be the users browser, it needs to come from the server of web 2.
The reason to that is that we can than do the checkIPrange and control the authentication.
WEB 1
----------------------
if (!checkIPRange()) { //check if range
<? echo "<A HREF=javascript
opwindow(' exit;
}
displayarticle();
----------------------
The IPRange function check
function checkIPRange () {
$ip_range = "xxx.xxx.xxx.1-xxx.xxx.xxx.254"; //IP Range
// Range
if ($_SERVER['HTTP_USER_AGENT'] == "PM") {
$ar = explode("-",$ip_range);
$your_long_ip = ip2long($_SERVER["REMOTE_ADDR"]);
if ( ($your_long_ip >= ip2long($ar[0])) && ($your_long_ip <= ip2long($ar[1])) ) {
return TRUE;
}
}
return FALSE;
}
On Web 2 after we done the authentication we want to send back the user to the first window on Web1.
Intially i did this
?>
<script language=javascript type='text/javascript'>
self.opener.location.href="<? echo $link ?>";
self.close();
</script>
<?
It sends the user back to the first window and refresh the page, but the problem is that i get the ip and user agent of the desktop browser, so i could not verify on web 1 that the login was correct using the checkipRange.
So i tried to do a form on web 1 and pass it over to web 2, to set the variables and send it back. That is not working as i get self.opener.document
is null or not an object.
if (!checkIPRange()) { //check if range
<form>
<input type='hidden' name='useragent' id='useragent' value='' />
<input type='hidden' name='remoteaddr' id='remoteaddr' value='' />
<? echo "<A HREF=javascript
opwindow(' </form>
exit;
}
print <<<EOT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Redirecting...</TITLE>
<script> alert(self.opener.document.forms['login'].useragent.value); </SCRIPT>
<SCRIPT language=javascript type='text/javascript'>
self.opener.document.forms['0'].useragent="<? echo "PM" ?>";
self.opener.document.forms['0'].remoteaddr="<? echo "xxx.xxx.xxx.1" ?>";
self.opener.document.forms['0'].action="<? echo $link ?>";
self.opener.document.forms['0'].submit();
self.close();
</SCRIPT>
</HEAD>
</HTML>
EOT;
exit;
Do anyone have an idea how to make this work, or you can not do this on two different servers.
I am not very good with the javascript, and seek some feedback on what i have done as i get an error self.opener.document is null or not an object and i have tried several things to try but run ouf option so i posteing it here to see if someone has an idea on what i doing worong or what i try to do is not possible.
So on my news site I call it web 1, a user click on an article, the user is taken to a webapge were it is asking to login, i created a script mixing php and javascript.
The user will intially be asked to click a link to validate the subscription. Web 2, will send a request back to the same page, but the header information would say what ip and useragent, it should be the users browser, it needs to come from the server of web 2.
The reason to that is that we can than do the checkIPrange and control the authentication.
WEB 1
----------------------
if (!checkIPRange()) { //check if range
<? echo "<A HREF=javascript

}
displayarticle();
----------------------
The IPRange function check
function checkIPRange () {
$ip_range = "xxx.xxx.xxx.1-xxx.xxx.xxx.254"; //IP Range
// Range
if ($_SERVER['HTTP_USER_AGENT'] == "PM") {
$ar = explode("-",$ip_range);
$your_long_ip = ip2long($_SERVER["REMOTE_ADDR"]);
if ( ($your_long_ip >= ip2long($ar[0])) && ($your_long_ip <= ip2long($ar[1])) ) {
return TRUE;
}
}
return FALSE;
}
On Web 2 after we done the authentication we want to send back the user to the first window on Web1.
Intially i did this
?>
<script language=javascript type='text/javascript'>
self.opener.location.href="<? echo $link ?>";
self.close();
</script>
<?
It sends the user back to the first window and refresh the page, but the problem is that i get the ip and user agent of the desktop browser, so i could not verify on web 1 that the login was correct using the checkipRange.
So i tried to do a form on web 1 and pass it over to web 2, to set the variables and send it back. That is not working as i get self.opener.document
is null or not an object.
if (!checkIPRange()) { //check if range
<form>
<input type='hidden' name='useragent' id='useragent' value='' />
<input type='hidden' name='remoteaddr' id='remoteaddr' value='' />
<? echo "<A HREF=javascript

exit;
}
print <<<EOT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Redirecting...</TITLE>
<script> alert(self.opener.document.forms['login'].useragent.value); </SCRIPT>
<SCRIPT language=javascript type='text/javascript'>
self.opener.document.forms['0'].useragent="<? echo "PM" ?>";
self.opener.document.forms['0'].remoteaddr="<? echo "xxx.xxx.xxx.1" ?>";
self.opener.document.forms['0'].action="<? echo $link ?>";
self.opener.document.forms['0'].submit();
self.close();
</SCRIPT>
</HEAD>
</HTML>
EOT;
exit;
Do anyone have an idea how to make this work, or you can not do this on two different servers.