Jump to content

Caesar

Members
  • Posts

    1,025
  • Joined

  • Last visited

    Never

Posts posted by Caesar

  1. If I understood.....

     

    <?php
    
    function FormatIP($IP) {
    
      if(preg_match('/[0-9]+\.[0-9]+\.[0-9]+\.[0-9][0-9][0-9]/',$IP)) {
        $ip = preg_replace('/([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)/','\\1\\2*.*',$IP);
      }
        else
        {
          $ip = str_replace(' ','',preg_replace('/([0-9]+\.)([0-9]+\.)([0-9]+\.)([0-9]+)/','\\1\\2\\3 20-80',$IP)); 
        }
    
      return $ip;
    }
    
    //$ip = '192.168.0.100';  <-- This will return 192.168.*.*
    //$ip = '192.168.0.10'; <-- This will return 192.168.0.20-80
    
    $p =  FormatIP($ip);
    
    ?>

  2. What happens if someone enters 'http:mydomain.com'? '...How about 'http:// whoops i have spaces and invalid characters here .com'?

     

    One can't assume that a simple check based on string or character position will account for users who blindly type without thinking. Most people ont he internet don't :-P

  3. By the way...in case that confused you, implementation would look something like this...

     

    <?php
    
    function CheckURL($url) {
    
      if(preg_match('/http\:\/\/[aA-zZ0-9\.]+\.[aA-zZ0-9]+?[\?\=\_\-\/[aA-zZ0-9]+/', $url)) $link = $url;
        else  $link = 'http://'.$url;
    
      return $link;
    }
    
    //// Assuming the POST variables have already been defined...
    
    $linkone = CheckURL($_POST['linkone']); 
    // If the link is 'google.com', 'http://google.com' will be returned.
    $linktwo = CheckURL($_POST['linktwo']); 
    // If the link is 'http://yahoo.com', the same value will be returned without changes.
    
    ?>

     

    ...But as stated...you want to make sure you check ALL user input to make sure no SQL injection or XSS is possible.

  4. simply use string function i think strrpos or strstr is enough and faster 

     

    Assuming all his links are formatted the same. This is user input we're talking about. So many things can go wrong and so many things can be entered.

  5. <?php
    
    function CheckURL($url) {
    
      if(preg_match('/http\:\/\/[aA-zZ0-9\.]+\.[aA-zZ0-9]+?[\?\=\_\-\/[aA-zZ0-9]+/', $url)) $link = $url;
        else  $link = 'http://'.$url;
    
      return $link;
    }
    
    ?>

     

    Though I caution that you should scrub/clean any user input and not assume that the url or link is valid to begin with. You'll want to check that as well.

  6. Not for this specifically....I doubt it. But to do something like that would require only a basic to intermediate understanding of PHP and HTML. You'll want to look into fopen() and fwrite() and understand how paths work, relative to where you are on the server. Knowing that, you should be able to write your code with no problem.

  7. If this is your server, then it's possible. Otherwise, the default settings may not allow a PHP script to access a file that isn't in a public folder. If the use of site/user based php.ini files is enabled, then it should be easy.

  8. Any particular reason why you'd be using .ini files for this?

     

    Also, yes, you can use PHP to write to files using something like a series dropdowns. In my opinion that's kind of clumsy and definitely want something like that limited by implementation of a user/account system.

  9. Assuming your quotes are in an array called $quotes

     

    <?php
    
      function random_quotes($quotes)  {
      
        $q = array();
      
          for($count = 0; $count <= 2; $count += 1) {
            $num = rand(0, count($quotes)-1);
            
              while(in_array($num, $q)) $num = rand(0, count($quotes)-1);
                array_push($q, $num);
          }
        return $q;    
      }
    
    ?>

     

    Without testing much, that should return an array with three random keys. You can then display your quotes by using a foreach loop.

     

    <?php
    
      $q = random_quotes($quotes);
      $i = 1;
    
      foreach ($q as $key)  {
        echo'<ul>'.$i.'. '.$quotes[$key].'</ul>';
        $i++;
      }
    
    ?>

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.