0

How do i make it redirect when its on article?id=1 to index.php this is just an example if you dont understand this maybe this example is better

<?php
    if (header('location: article?id=1'==1)) 
    {
    header('location:index.php')
    }
?>

Sorry for my noob coding and thanks to you all for helping me i have tried some different things that i thought might work but i want to know from someone who knows more than me

1
  • header() OUTPUTS a header. it has no return value and cannot be used to match/test against anyhing. php.net/header. You probably want if ($_SERVER['REQUEST_URI'] == '...') or similar instead. Commented Apr 10, 2014 at 21:09

3 Answers 3

2

PHP puts all query string keys and values in the $_GET superglobal associative array:

if (isset($_GET['id']) && $_GET['id']==1) {
  header('Location: http://example.com/index.php');
}

Also, be sure to use the full URL with Location: headers. While most browsers will work without it just fine, it's good to be compliant with the RFCs.

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

2 Comments

Dosen't do anything when i reload the page it doesen't redirect me why might it not work?
@EasierNameToReplyTo Make a page with only this code, and let me know if it doesn't work.
1
if(isset($_GET['id']) && $_GET['id']==1){
 header('Location: http://www.yoursite.com/index.php');
}

Comments

0

You can use $_GET this way:

if ($_GET['id'] == 1) {

    header('location: http://example.com/index.php');
 }

1 Comment

Doesen't work plz help it just does not redirect me any other way i could do it

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.