php var to JS var with redirect

oiwio

New Member
Messages
214
Reaction score
0
Points
0
Im trying to reirect after a user gets a certain condition and carry over two variables to the redirect page. Heres the script, I think Im going to have to convert a php variable to a javascript variable

PHP:
$page = $_GET['page']
$attack = $_POST['attack'];
printf("<script>location.href='victory.php?attack=$attack&page=$page'</script>");

can anyone help me? Ive looked around on the web for a while and cant find a solution
 

bonzo meier

Member
Messages
47
Reaction score
0
Points
6
hi,

this is basically supposed to work, but you should handle the variables like this:
Code:
$page = $_GET['page'];
$attack = $_POST['attack'];
printf("<script>location.href='victory.php?attack=".$attack."&page=".$page."'</script>");

but note that the new $attack-variable in the url is now GET! so if your victory.php has another "$attack = $_POST['attack'];" in it, it won´t read the variable unless you change the method to $_GET.

peace,
bonzo
 

oiwio

New Member
Messages
214
Reaction score
0
Points
0
Ill try it, but victory.php is GET

so far, it is not working
 
Last edited:

bonzo meier

Member
Messages
47
Reaction score
0
Points
6
ok, in the url you have posted the variables are treated as part of the string in printf(). but this should actually work if you change your script as i suggested in my first reply...

oh and by the way, is there a special reason why you use printf() in the first place? because as you don´t apply any formatting parameters, you should best go as simple as
Code:
print "<script>location.href='victory.php?attack=".$attack."&page=".$page."'</script>";

peace, bonzo
 

oiwio

New Member
Messages
214
Reaction score
0
Points
0
I checked it again today and it was working, so thank you for your help. I guess it just took a little time to update the server
 
Top