0

I have a php script which can take some GET params. I would like to know how I can call the script with a different param inside the script.

I want to achieve something like this:

if ($param == "authorise") {
    //call the same script but use the $param, getAccountDetails"
    i.e http://mywebsite.com/?param=getAccountDetails&var=ivar&foo=bar
}

3 Answers 3

1

You could just modify the $_GET array at the top of the script depending on what's inside it:

if(isset($_GET['authorise'])){
    $_GET['do_some_secret_thing'] = 'whatever';
}
// run the rest of your logic LIKE A BOSS.

There might be some more wizardy way of doing it, but that'd work and is fairly straightforward.

Good luck!

Sign up to request clarification or add additional context in comments.

5 Comments

but how could I initially refresh the page with the new GET? Should I use header()?
Great way to test things, but can be hard to debug later. @XcodeDev Just call the page with ?param=whatever in the URL.
This would only work if the switch/if statement that checks for 'whatever' is below the case or if for 'authorize'. You probably already know this, but just to clarify: Changing the $_GET and $_POST arrays does not resubmit a request.
So, using my example, if somebody shows up to index.php?authorize=1, you want to redirect them to index.php?authorize=1&do_some_secret_thing=whatever ? If that's what you want to do, I'd be curious to know why.
As would I. The point there was to note that if the statement that checks for do_something_secret=='whatever' is above the if statement you wrote, the code within the if statement that checks for do_something secret would not be executed.
0

Use sessions

http://php.net/manual/en/features.sessions.php

sessions are used to add information to the client so they can be retrieved later.

Comments

0

The simplest thing I can think of would be to redirect the user to the script with the new GET variable.

if( $_GET['abc'] == 1 ) {
    header( 'Location: '.$_SERVER['PHP_SELF'].'?abc=2' );
}

If you would like to do this without exiting the running PHP script, take a look at cURL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.