redirect - header() not working in php when the url contains parameters? -


so i'm using $_get capture url use later when use $_get wont redirect!


here's sample code: url : http://localhost/project/active.php/?s=ieugfshd&h=qwuyrbcq&i=1

php code:

<?php include 'init.php'; $s = trim($_get['s']); $h = trim($_get['h']); $i = trim($_get['i']); $q = key_check($s,$h,$i); if($q == 1) { header("location:password_active.php"); exit; } if($q == 0) { header("location:login_failed.php"); exit; } ?> 


edit:
key_check( ) function

function key_check($k1,$k2,$id) { $query = mysql_query("select key1 users user_id = '$id'"); $key1 =mysql_result($query,0); $query = mysql_query("select key2 users user_id = '$id'"); $key2 =mysql_result($query,0); $y=strcmp($k1,$key1); $z=strcmp($k2,$key2); if($y || $z == 0) { return 1; } else { return 0; } } 

now when try this, got "1" i'm getting

this web page has redirect loop

but password_active.php doesn't have redirects. it's html page.

the url you're using access script is:

http://localhost/project/active.php/?s=ieugfshd&h=qwuyrbcq&i=1 

this loads active.php, role , tries send following header :

header("location:password_active.php"); 

the browser recieves header, , tries resolve relative url adding password_active.php after last slash before query string (that ?s=xxx string).

so browser loads:

http://localhost/project/active.php/password_active.php?s=ieugfshd&h=qwuyrbcq&i=1 

this loads active.php again, role again , send again same header, , loads page:

http://localhost/project/active.php/password_active.php?s=ieugfshd&h=qwuyrbcq&i=1 

again. , again. , again. after several tries, browser understands going wrong , stops.

you should use absolute url in http header:

header("location: /project/password_active.php"); 

also, please note how http headers should written, according standard.


random notes :

  • according file names, $s , $h both passwords. should hash them, , not passing them via url.
  • if($y || $z == 0) unlikely work think, since evaluated if y or not z in pseudo code, while may have wanted if not y , not z password checking.

also, point calling exit() after location header. should never forget that, important , may cause trouble in scripts if forget them.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -