-5

Checking Array element using if condition.

 $investor_array = explode(",",$project[project_investor_id]);

                       foreach ($investor_array as $investor) {

                           echo $investor;

                            if($investor!==$user_data['id']){

                                 header('Location: error.php');
                                 exit;
                             } 
                       }  

Please let me know how this make work if the $investor_array is like 1,26,29,30,39,48 and my $user_data['id'] = 26

Updates: On my app investor can login and see their project. But they can check other project by changed the ID like

 http://192.168.1.100/srscrm/project-details-user.php?project=34

Thank You

4

3 回答 3

3

使用 PHP 的 in_array 函数http://php.net/manual/en/function.in-array.php

$investor_array = explode(",",$project[project_investor_id]);
if(!in_array($user_data['id'], $investor_array)){
   header('Location: error.php');
   exit;
} 
于 2013-09-10T13:11:21.857 回答
0

尝试这样的事情:

$project="34";
$pro_id=base64_encode($project);
http://192.168.1.100/srscrm/project-details-user.php?project=$pro_id

在第二页

使用这个解码:

$pro_id=base64_decode($project);

如果投资者在 url 中输入 34,那么它会被解码,因此投资者什么也看不到。

于 2013-09-10T13:35:36.573 回答
0

如果要检查元素是否在数组中,请使用此函数:

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) http://php.net/manual/de/function.in-array.php

回答了你的问题?

于 2013-09-10T13:11:03.340 回答