fou2enve Posted May 24, 2007 Share Posted May 24, 2007 I have a login page that posts to itself along with a url attached (ie login.php?url=protectedpage.php?ID=9230&B=4949 ). the problem I'm having is getting anything after the & to stick. Here's what i mean: if (isset($_POST['name']) || isset($_POST['pass'])) { // form submitted // check for required values if (empty($_POST['name'])) { die ("ERROR: Please enter username!"); } if (empty($_POST['pass'])) { die ("ERROR: Please enter password!"); } if ($password="password") { // if a row was returned // authentication was successful // create session and set cookie with username session_start(); $_SESSION['auth'] = 1; setcookie("username", $_POST['name'], time()+(60*5)); echo "Access granted!"; $url = (isset($_GET['url'])) ? "$_GET['url']" :'index.php'; echo "<meta http-equiv=".'"'.'refresh'.'"'.' content="'."12;url=$url".'">'; echo $url; } else { // no result // authentication failed echo "ERROR: Incorrect username or password!"; } } else { // no submission // display login form ?> <html> <head></head> <body> <center> <form method="post" action="login.php?url=<? echo $url; ?>"> Username <input type="text" name="name" value="AuthorizedUser"> <p /> Password <input type="password" name="pass"> <p /> <input type="submit" name="submit" value="Log In"> </center> </body> </html> <?php } ?> im using $url=$_GET['url']; to get the URL and then later on in the script echoing $url into a meta refresh after a successful auth (actual auth process uses mysql but i pulled that out for now) but when the outputs i get: protectedpage.php?ID=9230 nothing else. I've tried using %26 in the initial url but that didnt help. I tried suing str_replace to try and replace & with %26 right before it outputted, but that didn't work. :-\ ideas? Link to comment https://forums.phpfreaks.com/topic/52878-solved-ampersands/ Share on other sites More sharing options...
corbin Posted May 24, 2007 Share Posted May 24, 2007 I would use url encode on the url when appending it to get... For example: <?php $newurl = "http://somesiteoryoursite.com/some/dir/"; $newurl = urlencode($url); ?> Link to comment https://forums.phpfreaks.com/topic/52878-solved-ampersands/#findComment-261106 Share on other sites More sharing options...
fou2enve Posted May 24, 2007 Author Share Posted May 24, 2007 corbin. you rock. Link to comment https://forums.phpfreaks.com/topic/52878-solved-ampersands/#findComment-261129 Share on other sites More sharing options...
corbin Posted May 24, 2007 Share Posted May 24, 2007 I think by default PHP decodes the encoded urls, but it may help you to know that urldecode does the exact opposite of urlencode ;p. (P.S. Oh, I know I rock ) Link to comment https://forums.phpfreaks.com/topic/52878-solved-ampersands/#findComment-261133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.