What is wrong with this code?

Discussion in 'PHP' started by jfontestad, Jan 18, 2007.

  1. #1
    This code works fine on *.nix machine, yet on my windows server it doesn't function. I've migrated many of my sites to my new windows server, but the code doesn't work. The templated files are not drawn. I have tryed to modify the code, but without any success. I have another version that uses the 'switch' function instead of the if. The file calls for a URL as follows:
    ?act=step1 -> should show step1 template
    ?act=step1do -> should show step1do template
    etc...

    But it's as if the $act isn't being passed.

    <?php
    
    $allowed = false;
    if (isset($_POST['pass']) && ($_POST['pass']!='')) {
        if ($_POST['pass']==$admin_pass) {
            setcookie("admin",md5($_POST['pass']));
            $allowed = true;
        }
    } else $allowed = ($_COOKIE['admin']==md5($admin_pass));
    
    $tmpl = new StyleObject();
    $cheats = new CheatObject();
    
    if (!$allowed) {
         $tmpl->drawteplate("admin_pass.htm");
         exit();
    }
    
    $tmpl->drawteplate("admin_main.htm");
    if ($act == "step1") {
        $tmpl->drawteplate("admin_step1.htm");
    } elseif ($act == "step1do") {
        if ($_POST['resent']==1)
            $tmp = $game->get_gameslist($_POST['url']);
        else
            $tmp = $game->get_gameslist($_POST['url']."?".$_POST['letter']);
        $tmpl->setvariable("count",$tmp);
        $tmpl->drawteplate("admin_step1do.htm");
    } elseif ($act == "step2") {
        $tmpl->setvariable("list",$game->getneededlist());
        $tmpl->drawteplate("admin_step2.htm");
    } elseif ($act == "step2do") {
        $tmpl->setvariable("number",$game->addnew());
        $tmpl->drawteplate('admin_step2do.htm');
    } elseif($act == "manual") { 
        $tmpl->drawteplate("admin_manual.htm");
    } elseif ($act == "manualdo") { 
        if ($cheats->add_game($_POST['title'],$_POST['cont']))
             $tmpl->setvariable("msg","Game added!");
        else
             $tmpl->setvariable("msg","This game already exist!");
    
        $tmpl->drawteplate("admin_manualdo.htm");
    }
    ?>
    PHP:
     
    jfontestad, Jan 18, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Where do you set the $act variable?

    If you've been relying on register globals on your *nix box, you should add $act = $_GET['act'] to see if that helps.
     
    rodney88, Jan 18, 2007 IP
  3. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #3
    wow...
    didn't even think of that.
    that did it.

    thanks
     
    jfontestad, Jan 18, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It's not that he didn't think to set it... he just assumed register globals to be on.

    jfontestad: in the nicest possible way, you have to stop that right now! By now *every* PHP developer should know how nasty and insecure register globals is. It's a security nightmare and I find it hard to believe that people don't know this.

    On top of that, I'm 99% sure that register_globals isn't even going to exist in the next major release of PHP, so you may as well get used to it...
     
    TwistMyArm, Jan 18, 2007 IP
  5. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #5
    ha...
    Thanks twistmyarm... hahaha like the username too... very unique.
    I'm just used to coding for a *.nix enviornment where globals were always on. Then I switched to windows... and didn't even think of it.
    But thanks you guys.
     
    jfontestad, Jan 19, 2007 IP