hello..
i am clicking url which redirects to my webpage. for example user is not login to that site then it redirects to login page. up to there its fine. after user login how can i redirect to requested page?

When redirecting them in the first place add into the redirect url "login.php?url=".urlencode(/path/to/page/from.php); Then on the form you place in the action= parameter the above path which is now in the $_GET tag.

When redirecting them in the first place add into the redirect url "login.php?url=".urlencode(/path/to/page/from.php); Then on the form you place in the action= parameter the above path which is now in the $_GET tag.

I have a same question..but i didnt got in this solution..can you please explain it..?

Thanks..

Give redirected url in form action...

Give redirected url in form action...

no....it is not the right thing.
you obserb in yahoo...or any thing.
in that when we clicks url from our mail then it redirects to current url if you are already loged in yahoo. otherwise it redirects to login page ...after it redirects to requested page.

firsttime you login yahoo page . after login it redirects to home page. if you request yahoo page with out login it redirects to login page after it redirects to requested page.

yes i understand...

Try creating session... if you are logged in it will show your process page else it redirect to home page...

if not logged in redirect to login page
after login, redirect to $_SERVER;
whatever page sent the user to the login page

It is simple really. When you link you include the url of that page in that link. So for example:

<?php
echo '<a href="anotherpage.php?previouspage='.urlencode($_SERVER['REQUEST_URI']).'">Test link</a>';
?>

Then anotherpage.php

$login_status=true;
if ($login_status==true) {
header('Location: http://yoursite.com'.$_GET['previouspage']); //no ending slash
}

I have a same question..but i didnt got in this solution..can you please explain it..?

Thanks..

It is simple really. When you link you include the url of that page in that link. So for example:

<?php
echo '<a href="anotherpage.php?previouspage='.urlencode($_SERVER['REQUEST_URI']).'">Test link</a>';
?>

Then anotherpage.php

$login_status=true;
if ($login_status==true) {
header('Location: http://yoursite.com'.$_GET['previouspage']); //no ending slash
}

Thanks... :)

Its working for me...but there is another problem raise..

I didnt get any hidden variables by this method..

do i have to pass all that through GET method ?
is it possible to get that variables through another method ?

Please help me.

Thanks. :)

do i have to pass all that through GET method ?
is it possible to get that variables through another method ?

Well other options include sessions and cookies. If you don't want that in the url then I would suggest using cookies. To use cookies place the following at the very top of every page.

setcookie('yummy',$_SERVER['REQUEST_URI'],time()+(60*60*24));

Then your redirect will be as follows.

$login_status=true;
if ($login_status==true) {
header('Location: http://yoursite.com'.$_COOKIE['yummy']); //no ending slash
}

Hope that helps...
---------------
For the Gurus:
Note that the php http referer is not always accurate as many browsers including my own do not send that information. Instead the http referer as mentioned in previous posts will at times be an empty string. That is why I suggest using the above method.

Hi,
I have following situation :

I Have form say form1, through form1 i input some data. this data will go to form2 in post method. now is it possible that i redirect the user to different form other than form2 say form3.

here condition is that i don't have access to form2 source code.

Please suggest what should i do in this case ?

Thanks,:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.