开发者

redirect and send variable via js

This is tricky..

I have two sites. Site A and site B. On another site (any site) I p开发者_JAVA技巧ost an affiliate link which takes you to site A where I have a script that redirects to site B (so the first link goes to site B after going through site A)

On site A, I have a variable which I'm trying to pass to site B but without putting it in the browser URL, e.g. http://www.siteB.com/?var=blabla

I was advised to try and use js to post the variables to site B. I tried putting this code in site A..

<body onLoad="submit_form();">
<form name="myform" action="http://www.siteb.com" method="POST">
  <input type="hidden" name="var" value="blabla"> 
</form>

<script language="javascript">
  <!--
  function submit_form() 
  {
    document.myform.submit()
  }
  -->
</script>

and on site B I tried using GET to get teh variable but nothing shows up

$var = $_GET['var'];
echo $var;

Must I somehow put the js var in header() ? I'm lost..


It's because your form is POST-ing the data, but you're trying to access the data from the $_GET array.

Try this:

$var = $_POST['var'];
echo $var;

$_POST contains data sent via POST, $_GET contains data sent via GET.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜