14:36
Обновить
Рекламный блок Форума
Реклама
Реклама
[Загрузить изображение на radikal не выходя с сайта]
  • Страница 1 из 1
  • 1
Отображение контента по критерию
soopermanДата: Суббота, 14.04.2012, 20:55 | Сообщение # 1
Логин: sooperman
Имя: kolia bondar
Сообщений: 100
Награды: 0
Репутация:
Замечания:
ID групы: 5
В шаблоне страницы:

Code
Code

<div align="center">  
      <p>  
          <b>Данный пример демонстрирует использование скрипта для ограничения просмотра контента в зависимости от возраста</b>  
      </p>  
</div>  
<hr>  
<?$PHPCODE$("http://phpexample.u coz.net/php/example006/example006.php")?>
PHP скрипт example006.php:

Code
<?  
if (count($_POST)>0)  
{  
      $___notjson=1;  
      if (!$_uid=u coz_getinfo("SITEUSERID"))  
      {  
          echo "$('#error').html('Невозможно идентифицировать пользователя')";  
          return;  
      }  
      $context = stream_context_create(array('http' => array('method' => "GET", 'header' => "Content-Type: text/xml",'timeout' => 8)));  
      $file = file_get_contents("http://phpexample.u coz.net/api/index/8-$_uid", false, $context);  
      if (strpos('200', $http_response_header[0]) || !$file)  
      {  
          echo "$('#error').html('Не могу получить данные, попробуйте позже')";  
          return;  
      }  
      $response = xmlrpc_decode($file,"utf8");  
      if ($response && xmlrpc_is_fault($response))  
      {  
          echo "$('#error').html('Не могу получить данные, попробуйте позже')";  
          return;  
      }  
      if ((int)$response['USER_AGE']<18) echo "$('#error').html('Вы не можете просмативать данный материал, т.к. вам не исполнилось 18 лет')";  
      else  
      {  
          file_put_contents('allowedusers', "$_uid\n", FILE_APPEND);  
          echo "$('#error').html('<img height=\"480\" width=\"640\" src=\"/php/example006/getimg.php\">')";  
      }  
      return;  
}  
?>  

<div id='error'><b>Фото: мокрая киска</b><p>*внимание, просмотреть фото вы можете только, если вам испольнилось 18 лет</p></div>  
<form action="/php/example006/example006.php" method="post" onsubmit="_uPostForm(this,{dataType:'script'});return false;" onerror="alert('Error');">  
<input type="hidden" name="none" value="1">  
<p><input type="submit" value="Просмотреть фото"></p>  
</form>

PHP скрипт getimg.php:

Code
Code

<?  
if (!$_uid=u coz_getinfo("SITEUSERID")) return;  
$lines=file('allowedusers');  
$allow=0;  
foreach ($lines as $line_num => $line)  
{  
      trim($line);  
      if ($line==$_uid)  
      {  
          $allow=1;  
          unset($lines[$line_num]);  
      }  
}  
file_put_contents('allowedusers',$lines);  
if (!$allow) return;  
header('Content-Type: image/jpeg');  
readfile("./example006.jpg");  
?>
  • Страница 1 из 1
  • 1
Поиск:

Вверх