Jump to content

Php - Wtf?


sfboy

Recommended Posts

This code is currently here

<?php

switch($op){

case 'h':
     echo "hello";
    break;
    
case 'b':
     echo "bye";
    break;
    
default:
    echo "no op switch detected";
    break;

    }
?>

now correct me if I'm wrong but whenever I go to

http://mtbstatic.com/sc/ebay/test4.php?op=b

the output should be bye

and

http://mtbstatic.com/sc/ebay/test4.php?op=h

the output should be hello

but the output is always "no op switch detected", this has never happened on any other host or am I just overlooking something really obvious in the code.

http://mtbstatic.com/sc/ebay/test4.php' target="_blank">

Link to comment
Share on other sites

Yeah, plus I never used to get data from forms, as long they had the same name tag as the variable. Now I need to use

$var = $_POST[$var]

what an arse! I guess it supposed to increase security but it means I need to modify all my pissing code.

Link to comment
Share on other sites

A more up to date way of doing it is to use


$mode = $HTTP_GET_VARS['mode'];
[/code]

You could just replace the variable with $HTTP_GET_VARS['mode'] directly, without assigning it to a variable at the top. Thats a bit messy though.

Always been done that way as far as I remember :turned:

Link to comment
Share on other sites

For future reference, to use $op when calling from a url with ?foo=bar is called a global variable.

You should never ever be able to do this. Most decent hosts have globals turned off, as its a super high security risk. I wont explain how, but trust me, if a host has globals turned on, i would consider changing just because of that fact.

And as far as i know, $_GET is still the fore runner over $HTTP_GET_VARS. I use $_GET, as does everyone else i know, and all the code i see uses $_GET. Mainly because coders, by nature, are highly lazy, and $_GET is a lot quicker to type then $HTTP_GET_VARS. :P

PHP 6 will be phasing out globals, and be disabling them by default, so i would try to avoid using them at all costs.

Link to comment
Share on other sites

A more up to date way of doing it is to use

$mode = $HTTP_GET_VARS['mode'];

You could just replace the variable with $HTTP_GET_VARS['mode'] directly, without assigning it to a variable at the top. Thats a bit messy though.

Always been done that way as far as I remember :turned:

For future reference, to use $op when calling from a url with ?foo=bar is called a global variable.

You should never ever be able to do this. Most decent hosts have globals turned off, as its a super high security risk. I wont explain how, but trust me, if a host has globals turned on, i would consider changing just because of that fact.

And as far as i know, $_GET is still the fore runner over $HTTP_GET_VARS. I use $_GET, as does everyone else i know, and all the code i see uses $_GET. Mainly because coders, by nature, are highly lazy, and $_GET is a lot quicker to type then $HTTP_GET_VARS. :P

PHP 6 will be phasing out globals, and be disabling them by default, so i would try to avoid using them at all costs.

Actually, $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV and $_SESSION variables deprecate the old $HTTP_*_VARS arrays and can be used regardless of the scope. There is no need to import them using the global statement within functions.

EDIT: So that's why globals should be turned off.

Edited by sfboy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...