Welcome Guest, Not a member yet? Register   Sign In
Avoide dublicate content
#1

[eluser]Tommy_DK[/eluser]
I have been reading about routes, but haven't found the answer my self. I hope that one of you have it:

I have a url like this:
x.com/controller/function/id

The problem is, that this shows the same content:
x.com/controller/function/id/something

Is it possible to avoid showing the results if there are more variables than expected?

I have thought about the following idea, but suspect that it can be done more professionally:

Code:
function category($chosen_category,$too_much)
    {
      if(!empty($too_much))
        {
          echo "The url is wrong... yadayada";
        }
      else
        {
          //The thing it should do when everything is fone
        }
    }

The idea was then to make the $too_much variable the last variable each time and always have that check.
#2

[eluser]xwero[/eluser]
You could do
Code:
function category($chosen_category)
{
   if(func_num_args() > 1)
   {
      // error
   }

   // other code
}
Another way to do it is to add a routing rule
Code:
$route['controller/function/\d.+'] = 'error/page';
If you use php5 you can do something like
Code:
$keys = array('controller/function/\d.+');
$route = array_fill_keys($keys, 'error/page');
This way you only have to maintain the excess parameter urls.

But i'm sure there are other solutions.




Theme © iAndrew 2016 - Forum software by © MyBB