+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Simple Header Script, Need Help

  1. #1
    dquigley's Avatar
    dquigley is offline x10 Sophmore dquigley is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Fresno, CA
    Posts
    249

    Simple Header Script, Need Help

    So I wrote this pretty simple script that is supposed to set the headers and such depending on your platform, however when I load it it does not show any text at all, however the page IS loading, just nothing shows up. So if you could help me find the error that would be great. Thank you in advance.

    <?

    $agent = getenv("HTTP_USER_AGENT");

    if (preg_match("/Win/i", "$agent")) {
    $style = "win";
    }
    else if (preg_match("/Linux/i", "$agent")) {
    $style = "linux";
    }

    $win_style = "<style type=\"text/css\">p, ul, ol, li
    {font-family:Arial;font-size:10pt;font-weight:normal;}
    h1 {font-family:Arial;font-size:16pt;font-weight:bold;}
    h2 {font-family:Arial;font-size:14pt;font-weight:bold;}
    strong {font-family:Arial;font-size:10pt;font-weight:bold;}
    em {font-family:Arial;font-size:10pt;font-weight:italic;}
    </sytle>";

    $linux_style = "<style type=\"text/css\">
    p, ul, ol, li {font-family:Times;font-size:12pt;font-weight:normal;}
    h1 {font-family:Times;font-size:18pt;font-weight:bold;}
    h2 {font-family:Times;font-size:16pt;font-weight:bold;}
    strong {font-family:Times;font-size:12pt;font-weight:bold;}
    em {font-family:Times;font-size:12pt;font-weight:italic;}
    </sytle>";

    ?>

    <HTML>
    <HEAD>
    <TITLE>Platform Matching</TITLE>

    <?
    if ($style == "win") {
    echo "$win_style";
    } else if ($style == "linux") {
    echo "$linux_style";
    }
    ?>

    </HEAD>
    <BODY>

    <h1 align=center>This is a level 1 heading</h1>
    <h2 align=center>Look! a level 2 heading</h2>
    <P align=center>This is a simple paragraph with some
    <strong>bold</strong> and <em>emphasized</em> text.</P>

    </BODY>
    </HTML>
    Last edited by dquigley; 12-11-2008 at 05:18 PM.

  2. #2
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Simple Header Script, Need Help

    The variable $linux_style has to be global, or it will not pass between scripts. Try this:
    Code:
    global $linux_style;
    global $win_style;
    global $style;
    
    or just:
    global $linux_style, $win_style, $style;
    It was quite a headache when I went through the same problem
    Last edited by Twinkie; 12-11-2008 at 09:16 PM.

  3. #3
    dquigley's Avatar
    dquigley is offline x10 Sophmore dquigley is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Fresno, CA
    Posts
    249

    Re: Simple Header Script, Need Help

    are you sure thats the problem? I looked at it and that doesnt seem correct, the book says to do it this way, and its only one script? I think the problem is actually a misplace ; " () or {} I did it all by the book so im sure I just made a typo.

  4. #4
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Simple Header Script, Need Help

    I'm sure, the fact that the variable is printed in a separate script means the variable has to be global.

  5. #5
    dquigley's Avatar
    dquigley is offline x10 Sophmore dquigley is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Fresno, CA
    Posts
    249

    Re: Simple Header Script, Need Help

    what do you mean in a seperate script? this is the same file.

  6. #6
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Simple Header Script, Need Help

    hey, try this:
    PHP Code:
    <?php // always start php scripts w/ <?php because some configs might not execute <? as php code

    $agent getenv("HTTP_USER_AGENT");

    if (
    stristr($agent'Win'))
    {

      
    $style "<style type=\"text/css\">p, ul, ol, li
    {font-family:Arial;font-size:10pt;font-weight:normal;}
    h1 {font-family:Arial;font-size:16pt;font-weight:bold;}
    h2 {font-family:Arial;font-size:14pt;font-weight:bold;}
    strong {font-family:Arial;font-size:10pt;font-weight:bold;}
    em {font-family:Arial;font-size:10pt;font-weight:italic;}
    </sytle>"
    ;

    }
    else 
    // If their user_agent doesn't match, then show the linux one (since unix, mac and others could possibly be more similar to linux than windows.
    {

      
    $style "<style type=\"text/css\">
    p, ul, ol, li {font-family:Times;font-size:12pt;font-weight:normal;}
    h1 {font-family:Times;font-size:18pt;font-weight:bold;}
    h2 {font-family:Times;font-size:16pt;font-weight:bold;}
    strong {font-family:Times;font-size:12pt;font-weight:bold;}
    em {font-family:Times;font-size:12pt;font-weight:italic;}
    </sytle>"
    ;

    }

    ?>

    <HTML>
    <HEAD>
    <TITLE>Platform Matching</TITLE>

    <?php

    echo $style;

    ?>

    </HEAD>
    <BODY>

    <h1 style='text-align:center'>This is a level 1 heading</h1>
    <h2 style='text-align:center'>Look! a level 2 heading</h2>
    <p style='text-align:center'>This is a simple paragraph with some
    <strong>bold</strong> and <em>emphasized</em> text.</p>

    </BODY>
    </HTML>
    Last edited by xPlozion; 12-11-2008 at 08:54 PM.

  7. #7
    dquigley's Avatar
    dquigley is offline x10 Sophmore dquigley is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Fresno, CA
    Posts
    249

    Re: Simple Header Script, Need Help

    I really need to fix the script I posted, not change it. Because I am doing lessons out of a book I would like to keep it the same that way I can go back later to reference what I did and such. Thank you for helping me and editing it, but I need to find the error I made, however I will note the <?php comment thats interesting.
    Thanks for help

  8. #8
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Simple Header Script, Need Help

    Separate as in a different set of <?php and ?> tags. I had the same problem with a script which loads a visit counter before the HTML and prints it to the page some ways down in the HTML, and this is the same sort of thing. Trust me, try it and tell me if it works =)

  9. #9
    tttony's Avatar
    tttony is offline x10 Sophmore tttony is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    ~ 10°10'27.10''' N 67°59'59'.59''' O elev. 457m
    Posts
    147

    Re: Simple Header Script, Need Help

    dont use preg_match try with xPlozion code, its better and your code there are some errors, ok you try to learn with a php book but that book its very old I recommend the official php manual
    PHP & MySQL Web Developer
    Free Domain co.cc

  10. #10
    dquigley's Avatar
    dquigley is offline x10 Sophmore dquigley is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Fresno, CA
    Posts
    249

    Re: Simple Header Script, Need Help

    well, where exactly do I put that then?
    Edit:
    This book isnt old its php6 which is the newest php and it was wrote like this year.
    Last edited by dquigley; 12-11-2008 at 09:19 PM. Reason: Automerged Doublepost

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Super Simple Script Error Need Help
    By dquigley in forum Programming Help
    Replies: 8
    Last Post: 12-10-2008, 09:47 PM
  2. Access to 300+ PHP scripts (2500 credits)
    By jonathanyaniv in forum The Marketplace
    Replies: 11
    Last Post: 06-03-2008, 10:58 PM
  3. Simple php script fails
    By Lonesome61 in forum Programming Help
    Replies: 7
    Last Post: 04-25-2008, 04:13 AM
  4. Replies: 8
    Last Post: 12-03-2007, 04:12 PM
  5. simple script
    By swirly in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 06-17-2006, 06:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers