Creating Function Newbie question

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Creating Function Newbie question

    Hi

    I have written a small bit of code for my web site that basically is
    anti hack code.

    $checking = ($HTTP_GET_VARS['UniqueNo']);
    if (ereg ("[^0-9]+", $checking) )
    {echo "Please Stop Trying to Hack This Site";
    exit;}

    I would like to change this into a function where I only have to enter
    the Http variable. into the functions brackets. How do I do it? Is it
    possible?

    many thanks

    Peter
    Motto "A smile aday keeps the blues away"

    [url]http://www.sci-comm.clara.net/[/url]

    Peter Wilson Guest

  2. Similar Questions and Discussions

    1. Creating datasource with mysql- newbie question
      Hi all, I have been using a program to connect to mysql database on my shared hosting. I am now setting up a site in dreamweaver and a datasource...
    2. Creating directories... : Newbie Question
      Hey all I have this is a script: <?php $city = $_GET; $state = $_GET; if($file_name !="") {
    3. Newbie Question: Can PHP communicate with a C function/program
      I have several library functions that have been created in 'C' which I would prefer not to have to re-write all of them to PHP. Is there a way to...
    4. newbie question: function overloading
      I need to define a method that performs differently when operated on objects of different type (overloading). Currently I use various if's to check...
    5. newbie question: creating a new record in a related file
      somaBoyMX wrote: You can do it with a Portal in the Contacts file. First, the relationship from the Contacts file as Master to the related...
  3. #2

    Default Re: Creating Function Newbie question

    On Sun, 6 Jun 2004 21:07:54 +0100, Peter Wilson <pwilson@sci-comm.clara.net> wrote:
    >Hi
    >
    >I have written a small bit of code for my web site that basically is
    >anti hack code.
    >
    >$checking = ($HTTP_GET_VARS['UniqueNo']);
    >if (ereg ("[^0-9]+", $checking) )
    >{echo "Please Stop Trying to Hack This Site";
    >exit;}
    >
    >I would like to change this into a function where I only have to enter
    >the Http variable. into the functions brackets. How do I do it? Is it
    >possible?
    >
    >many thanks
    >
    >Peter
    >Motto "A smile aday keeps the blues away"
    >
    >[url]http://www.sci-comm.clara.net/[/url]
    // usage: check_if_hacking([variable]);
    function check_if_hacking($variable = false)
    {
    global $_GET;

    if ($variable === false)
    $variable = $_GET['UniqueNo'];

    if (ereg("[^0-9]+", $variable))
    {
    die("Stop trying to hack this site");
    }
    }

    // to use the function use either of the following methods
    check_if_hacking($_GET['UniqueNo']);

    or:

    check_if_hacking(); // will use $_GET['UniqueNo']; by default if no variable is passed.

    Shane Lahey Guest

  4. #3

    Default Re: Creating Function Newbie question

    Shane Lahey spilled the following:
    > On Sun, 6 Jun 2004 21:07:54 +0100, Peter Wilson
    > <pwilson@sci-comm.clara.net> wrote:
    >
    >>
    >>$checking = ($HTTP_GET_VARS['UniqueNo']);
    >>if (ereg ("[^0-9]+", $checking) )
    >>{echo "Please Stop Trying to Hack This Site";
    >>exit;}
    >>
    >>I would like to change this into a function where I only have to enter
    >>the Http variable. into the functions brackets. How do I do it? Is it
    >>possible?
    >>
    > // usage: check_if_hacking([variable]);
    > function check_if_hacking($variable = false)
    > {
    <snip>
    > }
    >
    Or for the really techno-funky version, use create_function to generate a
    lambda function.

    But I can't help noticing that checking the GET var has at least one digit
    in it is hardly going to keep out the most determined of hackers. Suggest
    you think of a better algorithm, since 'UniqueNo' will probably be
    appearing in your pages, it won't take much effort to find a valid match.

    C.
    Colin McKinnon Guest

  5. #4

    Default Re: Creating Function Newbie question

    >But I can't help noticing that checking the GET var has at least one digit
    >in it is hardly going to keep out the most determined of hackers. Suggest
    >you think of a better algorithm, since 'UniqueNo' will probably be
    >appearing in your pages, it won't take much effort to find a valid match.
    >
    >C.
    I idea was to stop the people from being able to break into the page to
    do some harm to the DB. I was told that if you can make the page drop by
    using contort characters they can then hack eh BD I have no idea how
    true this is but the little bit of code stopped it from happening any
    way. Also a good point to start learning how to make functions simple
    code.

    Many thanks for the help

    Peter
    Motto "A smile aday keeps the blues away"

    [url]http://www.sci-comm.clara.net/[/url]

    Peter Wilson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139