0

I have a redirect PHP page which checks a URL Parameter and redirects to one of two pages depending on if the variable 'shore' is either 1 or not. My problem however, is that no matter what I do, the page is redirecting to the first option. Can anyone see anything obvious that I am missing?

Many thanks

<?php

  require_once('Connections/ships.php');

if ($_GET['shore'] = "1") {
   header( 'Location: shore_establishment.php?ship_id=' .urlencode($_GET['ship_id']) . "?shore=1");
   //echo"first";
} else if ($_GET['shore'] = "0") {
    header( 'Location: shipinfo.php?ship_id=' .urlencode($_GET['ship_id']). "?shore=0");
   //echo"second";
};

?>
0

2 Answers 2

1

Like, @CommuSoft said, and your second ? in your $_GET request should be an & instead.

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

3 Comments

Just to clarify do you mean the ? before shore=1
Yes, and any other parameters after that, that you wish to add.
@PHPglue: didn't noticed that :S. @user2406993: indeed, the HTTP standard specifies that URLs with a query should be written as protocol://server/path/page.ext?arg1=val1&arg2=val2&arg3=val3. Although I would agree the & makes life complicated.
0

You should use == instead of = to check the content of a variable

Furthermore I would advise you to use else instead of else if since there are only two options (this is more robust and in case in the end a third variable is introduced, the page would still do something).

1 Comment

thank you, I actually set it to if = 0 and if !=0 but i removed this to try and find my error.

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.