ted_chou12 Posted January 2, 2007 Share Posted January 2, 2007 Below is my script:[code] <?php $page = "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}";//when I try only $_SERVER['PHP_SELF'], the redirection works, but when I try it with query, it only to the page name without the query. } break;case "login": $username = isset($_POST["username"])?$_POST["username"]:""; $password = isset($_POST["password"])?$_POST["password"]:""; if ($username=="" or $password=="" ) { echo "<h1>Username or password is blank</h1>"; clearsessionscookies(); header("location: $page?returnurl=$returnurl"); } else { if(confirmuser($username,$password)) { createsessions($username,$password); if ($returnurl<>"") header("location: $returnurl"); else { header("location: /users/confirm.php"); } } else { echo "<h1>Invalid Username and/Or password</h1>"; clearsessionscookies(); header("location: $page?returnurl=$returnurl"); } } break;case "logout": clearsessionscookies(); header("location: index.php"); break;}?>[/code]please see the orange text at the first line.ThanksTed Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 What do you see if your echo $page? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 2, 2007 Author Share Posted January 2, 2007 opps sorry, i think is because i have the confirm.php at the bottom...yeap when i see echo page, its fine, is this:header("location: /users/confirm.php");thats having the problembut now I changed it to thisheader("location: $page");it doesnt work at all now, it redirects to the index.php after login, no matter whan $page is...Can you help me with this?Thanks Ted Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 What do you see if your echo $page? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 2, 2007 Author Share Posted January 2, 2007 what is 'HTTP_REFERER'? i checked the manual, but i dont understand...The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. does it give me the previous url? if not, what does give me the previous filename of the page? i need the previous page filename eg. "/test.php?id=test" <<< something like this would work.Ted Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 Can you read? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 2, 2007 Author Share Posted January 2, 2007 Nope, it doesnt work, I dont understand, why doesnt this work?[code] <?php $page = "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}";//Get the page url echo $page;// echo page } break;case "login": $username = isset($_POST["username"])?$_POST["username"]:""; $password = isset($_POST["password"])?$_POST["password"]:""; if ($username=="" or $password=="" ) { echo "<h1>Username or password is blank</h1>"; clearsessionscookies(); header("location: $page?returnurl=$returnurl"); } else { if(confirmuser($username,$password)) { createsessions($username,$password); if ($returnurl<>"") header("location: $returnurl"); else { header("location: $page");//redirects to page after login } } else { echo "<h1>Invalid Username and/Or password</h1>"; clearsessionscookies(); header("location: $page?returnurl=$returnurl"); } } break;case "logout": clearsessionscookies(); header("location: index.php"); break;}?>[/code]when i try echo $page it shows me this:/users/confirm.php?confirm=gbeditbut after login, it does redirect to this but it redirects to the index.php of that folder, i dont understand why.. Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 The Location header requires a fully qualified url to be reliable. Meening....[code]http://yoursite.com/users/confirm.php?confirm=gbedit[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 2, 2007 Author Share Posted January 2, 2007 nope doesnt work, because the user folder will always be included, so i did this:http://mysite.com$pagebut it doesnt work, it just redirects me to http://mysite.com and no $page, but when I echo, the $page comes out right. Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 Your not defining $page within the same case. Also... you cannot echo ANYTHING to the screen prior to a call to header(). Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 2, 2007 Author Share Posted January 2, 2007 okay, is no problem now, i think is because I am having some paging problems, because confirm.php includes this page i posted (login.php) so the variables cannot be passed while the login.php is checking the login, because the url is already so messed up so ive set a session to it:$_SESSION['page'] = $page;in order to pass the variable to the next page, header("location: {$_SESSION['page']}");so now the header redirection works fine :)so happy now i got it right, Thanks thorpeTed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.