tags:

views:

369

answers:

5

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");
        } 
    }
+1  A: 

you could possibly check the $_SERVER['QUERY_STRING'] variable to see if it contains 'ask_question'

edit: fixed the typo

John Boker
should be $_SERVER['QUERY_STRING']
Zed
+4  A: 
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.

Lucky
I have this `print_r($_GET['ask_question']);` in my body. It returns nothing in all pages, not even at http://localhost/codes/index.php?ask_question.
Masi
+1  A: 

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.

Cahlroisse
+2  A: 
$location = "test.php";
if(isset($_SERVER['QUERY_STRING']))
{
    header("Location:".$location . "?" . $_SERVER['QUERY_STRING']);
}
else
{
    header("Location:".$location);
}
Chacha102
This answer shows me that I need to use different method to get the URL of the site which the user last visited. - I know that I can get that data in Google Analytics, but I am not sure how I can get it by PHP.
Masi
I opened a new thread based on your answer at http://stackoverflow.com/questions/1250729/to-get-the-coming-url-of-the-user
Masi
+1  A: 

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.

Andrew Moore