1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP expression different results

Discussion in 'PHP' started by cr3at1v3, Jul 29, 2017.

  1. #1
    hi all, i would like to ask what is the solution.

    using the code below:
    <html>
    <head>
    <?php
    $test = "http://www.consiariat.us/xxx/ip/2.90.208.84.xxx";
    $t = intval((file_get_contents($test) + (2 * 60)) * 1000);
    ?>
    <?php echo $t; ?><br>
    <?php echo file_get_contents($test);?>
    </body>
    </html>
    PHP:
    gives different results using different hosting sites.
    the code is used in heliohost.org:
    http://simple.heliohost.org/faucet/test.php
    Result:
    1501322878000
    1501322758

    but when code is used in atspace.com
    http://consiariat.us/02faucet/test.php
    Result:
    -1915675600
    1501322758

    what is seems to be the problem. why at atspace it is giving negative value?

    thanks.
    SEMrush
     
    Solved! View solution.
    cr3at1v3, Jul 29, 2017 IP
    SEMrush
  2. #2
    I had a play around and couldn't get that negative number. What happens if you try this:
    <html>
        <head>
            <?php
    $test = "http://www.consiariat.us/xxx/ip/2.90.208.84.xxx";
    $contents = file_get_contents($test);
    $t = intval($contents + (2 * 60)) * 1000;
    $u = intval($contents) + (2 * 60 * 1000);
    $v = (intval($contents) + (2 * 60)) * 1000;
            ?>
            <?php echo $t; ?><br>
            <?php echo $u; ?><br>
            <?php echo $v; ?><br>
            <?php echo "|{$contents}|<br/>";?>
    <?php echo intval($contents);?>
        </body>
    </html>
    PHP:
    You don't have to break your code down but when it's playing up it can help the debugging process.

    My variations have the brackets around the numbers at the end differently - was just seeing what different answers I get.
    I suspect the intval only needs to be around "contents" since the 2, 60 and 1000 are known to be integers, unless they're also going to be variables once you get past this problem.
    I've put the pipes around the echo of $contents so that you can see if the other host is finding hidden characters that it's parsing differently.
     
    sarahk, Jul 29, 2017 IP
  3. cr3at1v3

    cr3at1v3 Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3

    hello, thanks for your quick reply. i have used your code. here are the results
    link: http://consiariat.us/02faucet/test.php
    Results:
    1.501322878E+12
    1501442758
    1.501322878E+12
    |1501322758|
    1501322758

    link: http://simple.heliohost.org/faucet/test.php
    Results:
    1501322878000
    1501442758
    1501322878000
    |1501322758|
    1501322758

    does it have to do with hosting settings?
     
    cr3at1v3, Jul 29, 2017 IP
  4. Blank ™

    Blank ™ Well-Known Member

    Messages:
    223
    Likes Received:
    18
    Best Answers:
    6
    Trophy Points:
    110
    #4
    Is atspace by any chance running your site on 32 bit or Windows machine?
     
    Blank ™, Jul 29, 2017 IP
  5. cr3at1v3

    cr3at1v3 Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    hi. may i know where to find if i am on 32 bit or windows? i am just on basic hosting.

    this is the only details i know of my hosting plan:
    • Unlimited Disk Space
    • Unlimited Monthly Traffic
    • 2 Domains Hosting
    • 5 Subdomains
    • Free DNS Server
    • PHP, Perl/CGI-BIN
    • 2 MySQL Databases
    • FTP Access
    • Unlimited POP3/IMAP E-mails
    • Instant Account Setup
    • Web-based File Manager
    • Easy-to-use Control Panel
    • Reliable RAID Backups
    • GRID Hosting Platform
    • Super Fast Servers
    • Reliable Data Center
    • Ultra Fast Network
    • 99.8% Uptime Guarantee
    • 24x7 Network Monitoring
    • 24x7 Ticket Support
    • Fully Upgradeable
     
    Last edited: Jul 29, 2017
    cr3at1v3, Jul 29, 2017 IP
  6. sarahk

    sarahk iTamer Staff

    Messages:
    26,451
    Likes Received:
    3,958
    Best Answers:
    111
    Trophy Points:
    665
    #6
    So it looks like both servers are giving the same results - just displaying the numbers differently.

    as for the hosting - there are websites that can look that up for you

    upload_2017-7-30_2-14-55.png
    upload_2017-7-30_2-15-38.png
     
    sarahk, Jul 29, 2017 IP
  7. cr3at1v3

    cr3at1v3 Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    thanks. i have issued a support ticket from atspace but they haven't replied yet. the files i am using are working fine in free hosting which is heliohost.org and have issues when used in paid hosting in atspace.com.
     
    cr3at1v3, Jul 29, 2017 IP
  8. hdewantara

    hdewantara Well-Known Member

    Messages:
    487
    Likes Received:
    45
    Best Answers:
    22
    Trophy Points:
    130
    #8
    For the negative number,
    I'm guessing this as the reason:
    http://php.net/manual/en/language.types.integer.php:
    So you may be interested to perform a little test, as follows:
    $int1 = PHP_INT_MAX;
    $int2 = PHP_INT_MAX+1; //overflowN
    
    echo 'int1 = ', $int1, PHP_EOL;
    echo 'int2 = ', $int2, PHP_EOL, PHP_EOL; //overflown
    
    echo 'inval1 = ', intval($int1), PHP_EOL;
    echo 'intval2 = ', intval($int2), PHP_EOL; //overflown
    PHP:
     
    hdewantara, Jul 29, 2017 IP
    sarahk likes this.
  9. cr3at1v3

    cr3at1v3 Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #10
    thanks for the reply. below are the results.

    atspace.com result:
    int1 = 2147483647
    int2 = 2147483648
    inval1 = 2147483647
    intval2 = -2147483648

    heliohost.org result:
    int1 = 9223372036854775807
    int2 = 9.22337203685E+18
    inval1 = 9223372036854775807
    intval2 = -9223372036854775808
     
    cr3at1v3, Jul 29, 2017 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Which means that atspace is running on 32bit... for what reason, I have NO idea. There is absolutely no reason to run ANYTHING on 32 bit these days. Even the lowliest laptop is running on 64bit.
     
    PoPSiCLe, Jul 29, 2017 IP
  11. cr3at1v3

    cr3at1v3 Greenhorn

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    thanks all for your response. maybe just have to remodel some of the codes. gonna use sarahk's suggestion.
     
    cr3at1v3, Jul 29, 2017 IP
  12. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #12
    Just take note that if any of your numbers exceed the limit for 32bit, it will return broken / weird results if run on such a platform. No matter how you format or try to work around it - if you use bigger numbers, it will break. Best way to fix it is to make sure you run on 64bit systems.
     
    PoPSiCLe, Jul 29, 2017 IP