JelloDude
JelloDude

Reputation: 2484

Redirect for specific query string value

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

Upvotes: 0

Views: 283

Answers (3)

Black Sheep
Black Sheep

Reputation: 6694

You can use $_GET this way:

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

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

Upvotes: 0

meta-nickname
meta-nickname

Reputation: 83

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

Upvotes: 1

Brad
Brad

Reputation: 163301

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.

Upvotes: 2

Related Questions