Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

How to force login before entering a page?

Asked Modified Viewed 6,547 times
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
asked
Member

Hello,

i have a page "infusions/myinfusion/mypage.php"

A guest can click on a link to that page but when he does the login.php should open and after successful login redirect to the mypage.php

Now i tried it via this:

if(!iMEMBER)redirect(BASEDIR."login.php?redirect=infusions/myinfusion/mypage.php");


But somehow it doesn't work. I thought the redirect flag is the one i need?

Second Question:
How can i read the current URL?
I thought it was FUSION_SELF but that is only the file?
0 replies

15 posts

C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

Just put this in a center panel, enable for public access on all pages..

if (isset($_POST['login']))

{

redirect(INFUSIONS."myinfusion/mypage.php");

 }



After he/she/it has logged in he/she/it is redirected to that page. ;)


2.

<?php
echo "http://".$settings['site_host'].FUSION_REQUEST;
?>
Edited by Craig on 07-08-2012 13:14,
0 replies
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
answered
Member

thanks Craig :)
but doesn't that mean that wherever a user logs in, he get's redirected to INFUSIONS.'/myinfusion/mypage.php'?

what i want is, when a guest enters INFUSIONS.'/myinfusion/mypage.php' i redirect to

BASEDIR.login.php'

if the user logs in now and only now it should redirect back to INFUSIONS.'/myinfusion/mypage.php'

a normal login should be handled as always.

so i guessed i redirect him not only to BASEDIR.'login.php',
but to BASEDIR.'login.php?redirect=/infusions/myinfusion/mypage.php'
or if he enters INFUSIONS.'myinfusion/mypage.php?param1=12'
to BASEDIR.'login.php?redirect=/infusions/myinfusion/mypage.php?param1=12'

so only if he enters a certain page this should happen
Edited by mawe4585 on 07-08-2012 13:19,
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

In that case...

if (iGUEST && FUSION_SELF =="mypage.php")

{

redirect(BASEDIR."login.php");

 }



Which means If user is a guest and on page mypage.php then redirect him to login.php ;)
0 replies
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
answered
Member

ok, but that would restrict me to mypage.php.

isn't there a redirect param in the login.php?
there is one when i look in the code, but i honestly don't know what happens to it.

i just don't like to write a panel for this purpose when there is a posibility to write one that i can use everytime i need something like this.

i know in the future there will be several pages where i want to use this system.
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

It wont restrict you if your logged in as a member.

If your logged in and on that page nothing will happen.

If your logged out as a guest and on that page it will happen.

That's what you asked for. ;)
0 replies
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
answered
Member

well it's not exactly what i wanted, thanks anyway.

i actually may have solved it but since i don't know the whole system i don't know if it's dangerous somehow:

In login.php find:

   if (isset($_GET['error']) && isnum($_GET['error'])) {
      if (isset($_GET['redirect']) && strpos(urldecode($_GET['redirect']), "/") === 0) {
         $action_url = cleanurl(urldecode($_GET['redirect']));
      }

and change to

   if (isset($_GET['redirect']) && strpos(urldecode($_GET['redirect']), "/") === 0) {
      $action_url = cleanurl(urldecode($_GET['redirect']));
   }
   if (isset($_GET['error']) && isnum($_GET['error'])) {

this is doing exactly what i want, i can call it like this:

if(!iMEMBER)redirect(BASEDIR.'login.php?redirect='.FUSION_REQUEST);

and it automatically redirects to the original page after successful login.

Do you think it is dangerous or something?
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

Hehehehe!!! Listen,

1. In post #1 you ask if a guest on mypage.php it redirects to login.php yes?

2. Then after you have logged in redirect back to mypage.php rite?

So my answers above are the solution.

Why make it difficult by modifying core files then we release v8 and you get angry coz your site don't work. lol

What Have I got wrong or are you asking 3 different questions in the one thread. I'm confused.

Help me out and I'll help you out. :)
0 replies
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
answered
Member

no you haven't got anything wrong, i'm just used to another developer-forum where i never get the straight-forward-way but the general way.

i always ask questions with an example, here it was the mypage.php.
what i meant was a general way to redirect to login.php and after login redirect back, not only for the mypage.php, but for any page if i have several.

it wouldn't make much sense to me to make a panel with an entry for every single page if i have 30 of them, it's just hard to maintain, so i searched for a general way.

i forgot to mention that i have more than one page where i need this, so i need to express myself more clearly in the future i think :D

sorry for this misunderstanding :)

i know it is not good to modify corefiles, but in this case i don't see another way. Would it be possible to add such a feature in V8 so that i don't have to change core-files when i install it? ;)
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

PHPFusion 7.02 does that.

Example, If I am viewing a forum thread as a guest then I login via this same viewthread page after login it does redirect me back to this view thread page I was on.
0 replies
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
answered
Member

thank you, i looked into that but i can't figure out how it's done :(
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

What?

Look do this...


1. Log out of this site...

2. Then go and view this download....
http://www.php-fusion.co.uk/downloads.php?cat_id=23&download_id=541

3. now on the user info panel at the left login.

See you were redirected back to the download page you were on.
0 replies
M
mawe4585
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
answered
Member

ah that's what you meant.. but that is only because the login panel on the side.
i want to show a loginpage in the middle because a guest can't enter that page. after login he should be redirected to that page he wanted to enter.

and that doesn't work here either, i just tried because i was logged out and wrote a reply, clicked send and landed on the forum-index-page. after login my reply was gone
0 replies
C
Craig
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
answered
Fusioneer

Yes well my solutions above will do that as you asked and it's resolved.

Good luck!

also this for in a panel....


if (isset($_POST['login'])  && FUSION_SELF =="login.php")

{

redirect(INFUSIONS."myinfusion/mypage.php");

 }


If he is on login.php then logs in he will be redirected to mypage.php ;)
0 replies
— 1 year later —
T
TalkFever
T
  • Member, joined since
  • Contributed 65 posts on the community forums.
  • Started 26 threads in the forums
answered
Member

I used this code, it works excellent for once a user is logged in. I have something maybe someone can help me with... My default homepage is home.php and my logged in user homepage is members.php.. how can I redirect logged in users to members.php when they click the home button rather than home.php? Can this be done with a panel or do core files have to be modified?
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

I Think you have to modifi the menu that is used on your site like somthing:

if (iMEMBER) {... go to members home
} else ... ( go to guest home
}
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 15 posts
  • Votes 0 votes
  • Topic users 4 members

4 participants

C
C
Craig 14
  • Fusioneer, joined since
  • Contributed 4,462 posts on the community forums.
  • Started 212 threads in the forums
M
M
  • Member, joined since
  • Contributed 84 posts on the community forums.
  • Started 34 threads in the forums
  • Started this discussions
T
T
  • Member, joined since
  • Contributed 65 posts on the community forums.
  • Started 26 threads in the forums
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet