1

Preface

This question is design centered and is going to be somewhat opinionated I suppose, so if you want to vote to close it that's cool - I understand - but I trust my peers up here.

Goal

Have the user click on a link, that requires them to be logged in, so redirect them to the login/registration page first. In my case it's all one page. And then after successful login - and I say that because registration performs an immediate login - direct the user to that page they originally requested.

Question

My gut tells me that I could simply pass the relative URL in the query string. However, there are two issues I see with that:

  • Joomla, for some reason, BASE64 encodes that address.
  • I really don't want to have to find a way to carry that around when rendering the pages (i.e. if there is a query string I have to make sure all the href attributes have it appended so when they post back it's persisted. I just don't like that.

So, to the question directly. If using the query string is the right way, then why does Joomla BASE64 encode it? And if it's not, what is the right way?

Community
  • 1
  • 1
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • 1
    i would use the query string and i know others do, as to joomla -no idea. –  Sep 05 '13 at 02:00
  • @Dagon, and I guess it's okay because I've built my own MVC framework, kept it simple, and I leverage the same controller for redirects. So, I can just pass another variable into that redirect letting me know I need to append the referring URL to the query string. – Mike Perrenoud Sep 05 '13 at 02:03

1 Answers1

1

I looked at the way YouTube handles this login access issue. They simple pass the URL and encode it into the $_GET variable. If you don't want to handle this $_GET variable on each page you could use sessions. Here is the link to the sessions manual. To set a session variable simple do:

<?php
session_start();
$_SESSION['continue_url'] = 'URL HERE';
?>

and to access and then delete the session

<?php
session_start();
$var = $_SESSION['continue_url'];
unset($_SESSION['continue_url']);
?>
Cameron
  • 632
  • 9
  • 24
  • So I thought about session too, but then I wondered, what's the scope of that session? Is it like ASP.NET where a session is built per browser window? – Mike Perrenoud Sep 05 '13 at 02:05
  • You can set a sessions expire time, and no its not dependent on the browser being open. Sessions are stored on the server, so they cannot be altered by the user either. Here is an article discussing how to set the session expire time, although therer are many other articles discussing the topic: http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes/1270960#1270960 – Cameron Sep 05 '13 at 02:08
  • The session should be created when a user first accesses the server correct? Of course that session will expire over time, and can then be recreated when they hit it if so. That's cool. And I leverage `Session` for the currently logged in user, so that might be a good spot for it. – Mike Perrenoud Sep 05 '13 at 02:12
  • yes, and the session should regenerate each time the user accesses the server – Cameron Sep 05 '13 at 02:21