Reputation: 141180
How can you manipulate the destination URL by the name of the starting url?
My URL is
www.example.com/index.php?ask_question
I do the following manipulation in the destination URL
if ($_GET['ask_question']) {
// Problem HERE, since if -clause is always false
if ( $login_cookie_original == $login_cookie )
{
include "/codes/handlers/handle_login_status.php";
header("Location: /codes/index.php?ask_question");
die("logged in - send your question now");
}
}
Upvotes: 1
Views: 1059
Reputation: 95344
You can retrieve values after the question mark by using the $_GET
super global. For the example ?ask_question=true
.
//is ask_question true?
if($_GET['ask_question'] == 'true') {
echo 'ask_question is true';
} else {
echo 'ask_question is not true';
}
For variables without values (like ?hello
), use $_GET
in such way:
if(isset($_GET['hello'])) {
echo 'hello is there';
} else {
echo 'hello is not there';
}
You've asked a lot of very basic questions about PHP and you don't seem to have a grasp on how the language works. I suggest giving the documentation a good read before your next question.
Upvotes: 1
Reputation: 83709
you could possibly check the $_SERVER['QUERY_STRING'] variable to see if it contains 'ask_question'
edit: fixed the typo
Upvotes: 1
Reputation: 61567
$location = "test.php";
if(isset($_SERVER['QUERY_STRING']))
{
header("Location:".$location . "?" . $_SERVER['QUERY_STRING']);
}
else
{
header("Location:".$location);
}
Upvotes: 2
Reputation: 536
I think you want to replace that with:
if (isset($_GET['ask_question'])) {
Which will only be true if it's contained in the URL.
Upvotes: 1
Reputation: 646
if (isset($_GET['ask_question'])) {
...
If you did a print_r() of $_GET you would see
Array
(
[ask_question] =>
)
which shows that ask_question is set, but is empty, so it tests false.
Upvotes: 4