Jump to content

[SOLVED] about the query redirection


ted_chou12

Recommended Posts

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.
Thanks
Ted
Link to comment
Share on other sites

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 problem
but now I changed it to this
header("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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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=gbedit
but after login, it does redirect to this but it redirects to the index.php of that folder, i dont understand why..
Link to comment
Share on other sites

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 thorpe
Ted
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.