Jump to content
xisto Community
Mordent

Altering Get On The Fly

Recommended Posts

Before I spend a little while writing out the necessary code for it to test if my theory is right or not, I was wondering if anyone's had any experience with altering GET variables. For instance, say I have a variable called "page" that's set to whatever page I want to load. Naturally the URL will look something like http://www.blah.com/index.php?page=wherever. Would it be possible to manually override that during some sort of initialisation (essentially an authorisation check), so that even if it says page=wherever it instead is actually equal to something else?

My thinking is something like

$_GET["page"] = "access_denied";
Hopefully my question's clear, as well as how I intend to use the functionality. I've got a handful of other things to develop first, so thought I'd leave this question out there while it's still on my mind. Any pointers appreciated!

Share this post


Link to post
Share on other sites

You can just do something like this.

$authorized = FALSE;if(!$authorized && $_GET['page']=='members_page') { include('registration_page.php');} elseif($_GET['page']=='members_page') { include('members_page.php');}

Share this post


Link to post
Share on other sites

I realise that I can do checks such as the one you posted, but the code that I'll be doing this particular bit of checking in is in a separate code block to my main chunk. Essentially I have the following structure:

Initialisation

Various Includes (functions; settings)

Session Initialisation

Authorisation Checking (ignoring page, the reasons as to why are a bit complex)


Page Include

Specific Authorisation Checking (i.e. type of member)

Page Template Initialisation

Page Template Completion

Page Template Parsing


Final Page Parsing

As can be seen, I effectively have two authorisation checks. One gets the user's level of access from the session information. If the user is not logged in then they are taken to the login screen (which I hoped could be easily achieved by "tricking" the later code in to using it as the data in the get variable before the page is included). This way round I can easily direct any non-members to a certain page without having to use headers (not that I'm adverse to them, I simply prefer other methods).

 

Hope this helps with explaining my question.

Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

A switch block for what? I have no problem with the way my site's working, nor the structure of it. My only question is whether GET variables can be set rather than just read. Looks like I'll whip up a hasty page to check it, as it'll be a bit quicker. :lol:Cheers anyway.

Share this post


Link to post
Share on other sites

I think what everyone has been trying to say is, yes it is possible to do such a thing, however it is not recommended.The $_GET variable isn't some godlike variable with magical properties, it's an ordinary array, just like if you were to define a new array called $EXAMPLE[] with strings for indices. However, doing something like this for authentication purposes is just sloppy. It is not good code etiquette. Sloppy code is more difficult to read and can cause confusion if another programmer takes over the project. It is better to do something like dolrich06 suggested in his first post. But if you are not willing to change the code you have currently, go ahead and set the get variable to whatever you want to. It will not cause any problems to the page.

Share this post


Link to post
Share on other sites

I think what everyone has been trying to say is, yes it is possible to do such a thing, however it is not recommended.
The $_GET variable isn't some godlike variable with magical properties, it's an ordinary array, just like if you were to define a new array called $EXAMPLE[] with strings for indices. However, doing something like this for authentication purposes is just sloppy. It is not good code etiquette. Sloppy code is more difficult to read and can cause confusion if another programmer takes over the project. It is better to do something like dolrich06 suggested in his first post. But if you are not willing to change the code you have currently, go ahead and set the get variable to whatever you want to. It will not cause any problems to the page.

Clearest answer so far, thanks. I suppose I should have made the "is it a suggested method" point as well, as that's certainly made things a bit clearer. Now I see what you've been getting at, I'll have a go at tweaking it to make it a bit less sloppy. Cheers again, folks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.