EkoDLuffy

msgs.php

Nov 30th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2.     include("config.php");
  3.     $sql=$dbh->prepare("SELECT * FROM messages");
  4.     $sql->execute();
  5.    
  6.     while($r=$sql->fetch()){
  7.         if($_SESSION['user'] == $r['name']){
  8.             $aktip = "bubble-right";
  9.         }else{
  10.             $aktip = "bubble-left";
  11.         }
  12.        
  13.         echo "<div class='urltag $aktip'><p><span class='name'>{$r['name']}</span><span class='msgc'>".urlf($r['msg'])."</span><span class='dat'>{$r['posted']}</span></p></div>";
  14.     }
  15.  
  16.     if(!isset($_SESSION['user']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])=='xmlhttprequest'){
  17.         echo "<script>window.location.reload()</script>";
  18.     }
  19.  
  20.    function urlf($text){
  21.         $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  22.         preg_match_all($reg_exUrl, $text, $matches);
  23.         $usedPatterns = array();
  24.        
  25.         foreach($matches[0] as $pattern){
  26.             if(!array_key_exists($pattern, $usedPatterns)){
  27.                 $usedPatterns[$pattern]=true;
  28.                 $text = str_replace  ($pattern, '<a href="'.$pattern.'" rel="nofollow">'.$pattern.'</a> ', $text);  
  29.             }
  30.         }
  31.      return $text;
  32.    }
  33.  ?>
Advertisement
Add Comment
Please, Sign In to add comment