SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast Damir Secki's Avatar
    Join Date
    Jul 2001
    Location
    Slovenia, Europe
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript value to PHP

    Hello folks
    Ok I need to pass my screen resolution value (that I get from JavaScript) to my php variable... of course without reposting )I hate redirects).
    Let me explain better.
    I am creating a 100% width portal.
    Now my site looks just fine if viewed with resolution 1280x.....
    Therefor I need to make some minor adjustments for minor resolutions.
    Now I've managed to include CSS files like:
    Code:
    <script language="JavaScript1.2">
    if (screen.width==1024){
    document.write('<link href="hd/ci1024.css" rel="stylesheet">');
    }else if (screen.width ==1280){
    document.write('<link href="hd/ci1280.css" rel="stylesheet">');
    }
    </script>
    Ok, so far so good.
    But now for some other adjustments I just need to make different layouts. That's why I need to include diferent php script.
    My site is constructed this way:
    index.php
    PHP Code:
    <?
    $pageTitle
    ="Home";
    include_once(
    getenv("DOCUMENT_ROOT")."/lib/config.inc.php");
    $pagePic="";
    $pageDescription="";
    $pageKeywords="";
    require_once(
    $cnfg_head_file);
     
    require(
    CNFG_HOME."/main.inc.php");
     
    require_once(
    $cnfg_footer_file);
    ?>
    now in head file I get this javascript value (screen_width).
    I need to pass this to php. so I could use:
    PHP Code:
    require(CNFG_HOME."/main$RES.inc.php" ); 

    Is this possible. I know for other pages is not difficult with use of cookies, sessions etc. But I need this for my first page (or better said - entry page).
    I thought about to use flash. So I can pass myJS value to flash movie that will process it and write the value into the DB wich can be then easyly retrieved by PHP.
    What do you think? are there any better ways to do the "magic" ??
    Thank alot 4 your answers
    Damir Sečki
    PHP (mainly cakePHP)/mySQL/JavaScript (jQuery)/HTML/CSS developer
    BlabberStar.com - Tratsche.de - Petteguless.it

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Damir Secki
    now in head file I get this javascript value (screen_width).
    I need to pass this to php. so I could use:
    PHP Code:
    require(CNFG_HOME."/main$RES.inc.php" ); 
    Is this possible. I know for other pages is not difficult with use of cookies, sessions etc. But I need this for my first page (or better said - entry page).
    I thought about to use flash. So I can pass myJS value to flash movie that will process it and write the value into the DB wich can be then easyly retrieved by PHP.
    What do you think? are there any better ways to do the "magic" ??
    Thank alot 4 your answers
    Hi,

    You would just echo out the js value like this:

    PHP Code:
    function get_res()
    {
      
    $res  "/main";
      
    $res .= "<script type=\"text/javascript\">document.write(screen.width);</script>";
      
    $res .="inc.php";
      return 
    $res
    }
      
     echo 
    get_res();
    // outputs '/main1024inc.php' or whatever res your on

    // for you particular problem
    require(CNFG_HOME.get_res()); 
    Hope this helps,
    -xDev

  3. #3
    SitePoint Enthusiast Damir Secki's Avatar
    Join Date
    Jul 2001
    Location
    Slovenia, Europe
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's working!
    I cannot believe it.

    Thank you very mutch!!!
    Damir Sečki
    PHP (mainly cakePHP)/mySQL/JavaScript (jQuery)/HTML/CSS developer
    BlabberStar.com - Tratsche.de - Petteguless.it

  4. #4
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Damir Secki
    It's working!
    I cannot believe it.

    Thank you very mutch!!!
    Glad to help.

    Cheers!

  5. #5
    SitePoint Zealot Arkkimaagi's Avatar
    Join Date
    Mar 2002
    Location
    Lappeenranta, Finland
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing thou, designing sites for different resolutions has a problem.

    I happen to have a double monitor setup here, my resolution is 3200*1200. I do not surf fullscreen, ever, it would suck.

    So maybe you should not check the screen width, maybe instead you should check the browser area width.

    just a thought

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or maybe you should just use percentages, as apposed to resolutions. I did a similar thing, with one of my sites, and it didn't work out. It was a pain to do, and certain resolutions still didn't work properly.


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
  •