Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Two simple questions



    Firstly, can anyone tell me how to do this in PHP:

    if (user's resolution is > 800 X 600)
    {
    does this
    }
    else
    {
    do that
    }

    Secondly, I've got a counter script, I want to change it so instead of writing a file to the current directory it writes it to a subdirectory called counters, here is the script:

    <?php
    $filename = current(explode('.', basename($PHP_SELF)));
    $fp = fopen("$filename.txt", "r");
    $count = fgets($fp, 1024);
    fclose($fp);
    $fw = fopen("$filename.txt", "w");
    $cnew = $count + 1;
    $countnew = fputs($fw, $count + 1);
    fclose($fw);
    ?>

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can't do that in PHP, you need JavaScript to look at the users screen, PHP is a server side language and thus would not be able to do that. So ask in the JS forum. As far as the filename thing with the counter...try changing all instances of $filename.txt to $counter/filename.txt and see if that works. But I really don't know for that one, never tried to do that.


    Jason

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Originally posted by Jason
    you can't do that in PHP, you need JavaScript to look at the users screen, PHP is a server side language and thus would not be able to do that. So ask in the JS forum. As far as the filename thing with the counter...try changing all instances of $filename.txt to $counter/filename.txt and see if that works. But I really don't know for that one, never tried to do that.


    Jason
    $counters/filename.txt???

    Shouldn't it be counters/$filename.txt since the counters directory is not part of the variable.

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    East Side/West Side
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $filename.txt? Shouldn't it be $filename, and have the variable contain something like "counted.txt"?

    But yes, it would be counter/$filename
    Rule #1 - Admin is always right
    Rule #2 - If Admin is wrong, see rule #1

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    161
    Thanks
    2
    Thanked 0 Times in 0 Posts
    $filename is the name of the file (e.g. if the script is in index.php $filename is set as index) I did this so I could add the script to multiple pages without editing it.

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Although you cannot sense resolution with PHP, you can get a similar effect by mixing JS and PHP:

    Get the resolution, insert it into a hidden form, have the form submitted on the clicking of a link.

    You may not get this, I hope you do tho.


  •  

    Posting Permissions

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