Results 1 to 9 of 9

Thread: I don't even know why this won't work

  1. #1
    Join Date
    Aug 2006
    Location
    America
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I don't even know why this won't work

    Okay, so I noticed a problem with a page I was putting on a bravenet.com website of mine, and I simplified the file again and again until it came down to this:
    Code:
    <?php
    
    if(!$step)
    {
    	echo "Step is null";
    }
    
    elseif($step == edit)
    {
    	echo "Step is set to \"edit\"";
    }
    
    ?>
    and for some reason that won't work on my bravenet.com site: http://www.cbts.halo2leagues.com/3.php but it will work on this free hosting site http://weberc2.coconia.net/3.php

    The problem is that, regardless of the variable's value in the query string, it ALWAYS reads the variable as null. If anyone can offer some insight into this, that'd be great.

  2. #2
    Join Date
    Nov 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    cause $step == edit
    not $step == "edit".

    remember to use your string values

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Also, you probably mean $_GET['step']. $step is not defined in the above code unless register_globals is set.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2006
    Location
    America
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It's designed to set the "step" variable's value in the query string, and as for the quotation marks around the variable in elseif ($step == "edit") it works regardless of whether they're in there or not on one server, but on the other it doesn't work at all regardless of either.

    To see what I mean, try typing http://weberc2.coconia.net/3.php?step=edit to see what the functional file would look like; however, the same portion of the same file on the other host reads the variable in the query string as null as shown here: http://www.cbts.halo2leagues.com/3.php?step=edit

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I know what it's designed to do, but it doesn't.
    as for the quotation marks around the variable in elseif ($step == "edit") it works regardless of whether they're in there or not on one server, but on the other it doesn't work at all regardless of either.
    It really shouldn't work without them. The other server likely has register_globals disabled, so $step is undefined.
    Code:
    <?php
    if(empty($_GET['step']))
      echo 'Step is empty';
    else if($_GET['step'] === 'edit')
      echo 'Step is set to "edit"';
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Nov 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok so if register_globals is off (which it should be)
    use this at the top of the code to reload vars at their names (like register_globals = on does)

    Code:
    <?php
    /*
    Reloads Cookies, Post vars, & Get vars as their own variables. 
     eg: 
      $_COOKIE['name'] : $name=value;  
      $_POST['somename'] : $somename = somenamevalue;
      $_GET['somename'] : $somename = somenamevalue;  
      
      so if you have a form name of "Firstname" you'll have:
        $_POST['Firstname'] OR $_GET['Firstname'] AND $Firstname
    	
    also a fix for register_globals = off
    */
    foreach ($_POST as $k=>$v) $$k=$v;    # Reload Posts
    foreach ($_GET as $k=>$v) $$k=$v;     # Reload Gets
    foreach ($_COOKIE as $k=>$v) $$k=$v;  # Reload Cookies
    ?>

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    But that totally defeats the point of not using register_globals in the first place. One might as well just re-enable it.

    Rather than using $_GET, $_POST, and $_COOKIE, you can use $_REQUEST, which contains values from all three.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Aug 2006
    Location
    America
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I see.. Could you please show me how to write code for this file using the $_request? I've already checked PHP.net and I still don't understand. Thank you very much.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php
    if(empty($_REQUEST['step']))
      echo 'Step is empty';
    else if($_REQUEST['step'] === 'edit')
      echo 'Step is set to "edit"';
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •