2017-03-11 137 views
0

我想找到一种方法来使它可以检查您当前的页面url是否包含像1,2,3,4,5,6,7,8,9,10,11,12,13,14,15这样的问题,问题是这种格式可能会永远在任何随机我需要这样做才能让其中一个数字不显示。检查当前页面网址是否包含某些词

目前我正在使用这样的系统来收集当前页面的URL。

$d = explode('?', $_SERVER['REQUEST_URI'], 2); 
echo 'http://' . $_SERVER['HTTP_HOST'] . $d[0]; 

但是我很陌生,我们可以简单地检查某些部分的URL,然后将其重定向回索引页。

编辑:这是我目前的代码(注意我正在使用laravel)。

if (strpos($d, '19') !== false) {  
    header('Location: http://example.com') ; 
} else { ?> 
<form class="form-horizontal" role="form" method="POST"> 
    {{ csrf_field() }} 
    @if(strlen($link->password)) 
     <p class="bg-warning" style="padding: 8px;">Enter password to continue</p> 
       <input type="password" name="password" class="form-control" style="margin-bottom:1.5rem;"> 
        @endif 
     <button type="submit" class="btn btn-primary">{{ $link->text }}</button> 
</form> 
<?php } ?> 

很抱歉的乱码,只是想弄清楚我怎么能做到这一点,而无需大量strpos反倒它现在回声出的形式,它没有。

+0

您的意思是:example.com/index.php?something=1,2,3,4,5 ... **或** example.com/index.php?1,2,3 ,4,5 ... **或** example.com/index.php?something=1&something2=2&something3=3&something2=4&something5=5 ... – Neil

+0

这将是这样的 - > xample.com/index.php ?id = 1然后另一个网址是xample.com/index.php?id=2 – Wayward

回答

0

如果您从url获取数据并且页面像这样test.php?id = 1您可以使用$ _GET方法直接访问数据并处理它们。在我的情况下,我访问直接$ _GET [“ID”],其返回值1,所以你直接比较价值。

谢谢。

+0

不是我在找什么,更新我的问题请查看 – Wayward

0

你很幸运,该功能是从字面上内置到PHP!

<?php 

echo $_GET['id']; //fetches whatever is after the id= (and before the next '&') example.com?id=WhateverComesHere 

?> 
+0

不是我在找什么,更新我的问题请查看 – Wayward

相关问题