Jump to content

login redirect


anatak

Recommended Posts

How can you redirect the user to the same page when he logs in ?

I want to make a function that is similar to the login function on phpfreaks.

here you are looking at a topic and then decide to login. after logging in you are automatically redirected to the topic you where viewing.

How can you do this ?

Is the best way to let the login go to a "thank you for logging in page" and then redirecting to the page you where viewing ?
Or can you do this in one step ?

I guess $_SERVER[] will have to be used but I am not sure exactly wich one and how.

anatak
Link to comment
Share on other sites

you could use a hidden input field on the login form. Is the login form displayed on every page? Just add the current page in the form.

Or, if they have to go to a seperate page to login, whenever a topic is being viewed set the topic in the session, then after logging in check if they have a topic in the session and redirect there.
Link to comment
Share on other sites

Jesirose,

do you know how to get the current page ?
that is my main problem.
the form is on my main page so I wanted to make the action point to the current page
<form method=POST action =<?php echo $_SERVER[PHP_SELF]; ?>
but that has some strange behaviour from time to time.

thanks
anatak
Link to comment
Share on other sites

you can use $_SERVER['REQUEST_URI'];

If it's on a topic, and your structure is like
/topics.php?id=1
then you'd just save $_SESSION['topic'] = 1;
and then redirect to your page. You don't need to know the whole URL, you should "know" it already.
Link to comment
Share on other sites

it is not really about a topic in a forum.
I was just using this as a reference.
the problem is that some pages have more than one variable in the url like index.php?p=3&id=2&sel=4&r=1
some other pages are like index.php?p=10&a=10

I was looking for a function that gets the full url of a page

anatak
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.