Page 1 of 1

Redirecting user depending on a uri query

Posted: Fri May 05, 2006 10:31 am
by Luke
I am working in MIVA (a merchant/online store solution) and I can not get under the hood of their code, so I need to find a way to cheat it. What I need to do is redirect users to a specific page depending on a variable set in the URI, but since I can't get into the backend code, I need to find a way to do it client-side... any ideas?

Posted: Fri May 05, 2006 10:48 am
by Luke
Maybe if I used an iframe that calls a php script... how would I make an iframe invisible/unable to be seen by visitors?

Posted: Fri May 05, 2006 11:02 am
by s.dot
To answer your second post

Code: Select all

<iframe src="somepage" height="0" width="0" frameborder="0" style="display: none;"></iframe>
Although I believe just the display: none part will do the trick. ;)

Posted: Fri May 05, 2006 11:02 am
by Weirdan
how would I make an iframe invisible/unable to be seen by visitors?

Code: Select all

<html>
<body>
  <style type='text/css'>
     iframe.hidden {
         float:left;
         margin-left:-100000;
     }
     /* or simply */
     /*
      iframe.hidden {
          display:hidden;
          height:1px;
      }
      */
     /* or */
     /*
      iframe.hidden {
           display:none;
      }
      */
  </style>
  <iframe id='hiddenFrame' name='hiddenFrame' class='hidden'></iframe>
</body>
</html>

Posted: Fri May 05, 2006 11:11 am
by Luke
ok... I have another question

in the iframe i called a php script which tests whether the $_GET variable is set and I set the $_GET variable (in the parent window). The iframe test says that it isn't set because the variable isn't being set in the iframe. How do I pass the query string from the URI to the iframe?

Posted: Fri May 05, 2006 11:14 am
by s.dot

Code: Select all

<iframe src="somepage.php?<?php echo $_SERVER['QUERY_STRING']; ?>">

Posted: Fri May 05, 2006 11:15 am
by Luke
The problem with that is that the parent frame needs to be a standard html page... can't put php in the parent frame... :(

I don't think this iframe thing is going to work... it won't redirect the parent frame without the use of javascript, so I may as well just put the javascript on the parent frame... but I am lame in javascript.

Is there a way to redirect with javascript depending on the query string?

Posted: Fri May 05, 2006 12:26 pm
by Luke
Just in case somebody comes to this thread with the same question... I solved the problem like this:

Code: Select all

<script language="javascript" type="text/javascript">
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return false;
}
var cat_code = getQueryVariable("Category_Code");
if(cat_code == "AR"){
        window.location = "http://www.somedomain.com/mm5/merchant.mvc?Screen=ARTS&Category_Code=AR&Store_Code=T";
}
else if(cat_code == "SP"){
        window.location = "http://www.somedomain.com/mm5/merchant.mvc?Screen=SPTF&Category_Code=SP&Store_Code=T";
}
</script>