Page 1 of 5 123 ... LastLast
Results 1 to 10 of 41

Thread: General Knowledge

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default General Knowledge

    These are just some random question's I have right now kinda relating to other posts I've made and kind of not....

    Is there a way to differentiation between refreshes and actually first visits possibly with a header request?

    Is the date function accessing my server's date, the computer I edited originally from on, or the user accessing the sites computers date settings?

    Will accessing a user's ip address with $_SERVER['REMOTE_ADDR'] ever come across to an anti-spam or virus program as a malicious site or present some question to the user?

    Not really relating to PHP but how does bandwidth work? I think I understand the basics of it. Like if you have 1000 users accessing 1byte of data at the same time you need 1+kbs of space free to have that function for all users. But the in a month feature I don't see how that works, unless they are just charging you by the chance that all your users hit you at the same time? Is that right or does it back up somewhere and the bandwidth can still be hit later by some of those same time users?

    Thanks for any explanation you can offer on these.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is there a way to differentiation between refreshes and actually first visits possibly with a header request?
    Not specifically, but you can set a cookie or session variable.

    Is the date function accessing my server's date, the computer I edited originally from on, or the user accessing the sites computers date settings?
    Of course the server's. PHP runs on the server; it doesn't have (direct) access to anything else.

    Will accessing a user's ip address with $_SERVER['REMOTE_ADDR'] ever come across to an anti-spam or virus program as a malicious site or present some question to the user?
    No. PHP runs on the server; client applications never see it. The client's IP address is given out in every network transaction, or the server wouldn't know where to send the requested data.

    Not really relating to PHP but how does bandwidth work? I think I understand the basics of it. Like if you have 1000 users accessing 1byte of data at the same time you need 1+kbs of space free to have that function for all users. But the in a month feature I don't see how that works, unless they are just charging you by the chance that all your users hit you at the same time? Is that right or does it back up somewhere and the bandwidth can still be hit later by some of those same time users?
    Bandwidth is not related to speed. It's the amount of data your users can download. If you have a 200GB/month bandwidth limit, your server can only serve a total of 200GB per month before being cut off.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (01-30-2009)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    OO thanks.

    About the bandwidth though so if you have your own server the limitations are just at the one time?

  5. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well, it's likely that your host or ISP will impose a limit of some sort.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (02-01-2009)

  7. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    ooo hah never thought of my isp limiting me but that does make sense now that i think of it. Thanks again.

    I got another question... I don't know if it needs to be here or just in "other" cause it might need to be a math equation. Is there an IsEven() function in php. I've seen it googling but it looks like it is more of a made up function for each I found, and that the user is not getting a true/false (0,1) but rather a 0,2,4,6,8 value and then determining it from there. Although that would work it seems like a lot more work to me if there is an equation or a function that could do the same trick. Like (x/2)= 0, or any decimal, which would be odd and the rest would be 1 and even.

    Thanks for any ideas you may be able to offer on this as well and for your other help as well.

  8. #6
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    php doesn't have a built in "is_even()" function, but you can make your own:

    PHP Code:
    /**
     * bool is_even  ( integer )
     * 
     * @param $int The integer value being evaluated
     * @return Returns true if $int is even. Returns false if $int is odd
     * 
     */

    function is_even($int) {
        
        if ( !
    is_int($int) ) {
            
            
    trigger_error('The is_even() function only accepts integers.'E_USER_WARNING);
            return;

                   
    // Or get rid of trigger_error(xxx) and replace it with: return false;
                   // to accept any input. This will cause odd numbers and decimals
                   // to return false.
            
        
    }
        
        
    $result $int == true false;
        
        return 
    $result;
        

    I don't know how well you know php, but when I first started learning php I would see a function that someone wrote for me and not really understand it, so I'll explain mine.

    is_even() as I wrote it, accepts an integer value only. The first part of the function checks to see if the input value is an integer, if not it will cause an error message to be displayed. If you want to change the type of error that is displayed, you can change E_USER_WARNING to one of the other E_USER constants http://www.php.net/manual/en/errorfunc.constants.php .

    If the input is an integer, the next part of the function is executed. I used the ternary operator:

    http://www.php.net/manual/en/languag...arison.ternary

    The value assigned to $result will depend on whether or not $int % 2 == 0 evaluates to true or false. If true, the first value after the ? will be assigned to $result, if false, the second value will be assigned.

    $int % 2 uses the modulus operator %. This means that the remainder of $int / 2 will be returned. When an even integer is divided by 2, there is never a remainder, so the result is 0. An odd integer divided by 2 has a remainder of 1. So if $int % 2 == 0, $int must be even, and this statement is true, so "$result = $int % 2 == 0 ? true : false" will assign true, the first value after the ?, to $result.

    The function then returns $result as either true or false.

    PHP Code:
    $int 23;

    if ( 
    is_even($int) ) {
        
        echo 
    "$int is an even number.";
        
    } else {
        
        echo 
    "$int is an odd number.";
        

    The above will output "23 is an odd number."

    There are some decimal numbers that will divide by 2 without a remainder, so this function needs to only accept integer values. You could change the trigger_error() if you to accept decimals and return false. Just get rid of "trigger_error(XXXX);" and put "return false;"

    Good luck,

    Jason
    Last edited by JasonDFR; 02-01-2009 at 09:30 AM. Reason: Spelling mistakes. Some of what I wrote didn't make sense after I read it. hehe...

  9. The Following User Says Thank You to JasonDFR For This Useful Post:

    bluewalrus (02-01-2009)

  10. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    OOO Thanks a bunch for the explanation and the code.

  11. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Uhm... better written as:
    Code:
    function is_even($n) {
      return $n % 2 === 0;
    }
    Of course, then it starts to seem a bit pointless to have a function for that at all...

    'Even' means 'divides exactly by 2'. For any numbers n and m, if n divides exactly by m, then n % m === 0: there is no remainder left over after division.
    Last edited by Twey; 02-01-2009 at 06:00 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  12. #9
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Yeah that is concise. My goal was to make things crystal clear and provide a great explanation so I dragged it out a bit. I prefer to be talked to like a two year old when I am trying to learn something.

    I disagree about it being pointless to have a function for this (as long as you are testing for even numbers more than one spot in your application or site). If you load any config file or function file with every page load, throw that function on there. "is_even()" is easier to code and most importantly understand. And it falls right in line with php functions like is_int, is_string, is_numeric, etc.

  13. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think foo % 2 === 0 is as much of an idiom in programming as are things like for loops. Nobody could really misunderstand it, and it truly is a very simple expression. I'm usually all for sectioning everything possible off into functions, but this isn't much above
    Code:
    function post_increment(&$n) {
      return $n++;
    }
    and
    Code:
    function add($a, $b) {
      return $a + $b;
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •