473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Problems with function return value

Hi all,

Help, I'm stuck! I've written the below function as part of my form data
filtering steps and for some reason It won't return the right value!

Can someone take a little look and tell me if you can spot any errors?

regards Tobierre

PHP Code:
function Stop_Form_Injection($post, $length)
{
$post = strtolower($post); //change input to lower case for search
purposes

//Check form input is allowable length
$length = strlen($post) - $length;
($length > 0) ? $filter[] = $length: $filter[] = false; //if form input
too long set false

$filter[] = strpos('to:', $post);
$filter[] = strpos('cc:', $post);
$filter[] = strpos('content-type:', $post);
$filter[] = strpos('\r', $post);
$filter[] = strpos('\n', $post);
$filter[] = strpos('charset=', $post);
$filter[] = strpos('mime-version:', $post);
$filter[] = strpos(',', $post);
$filter[] = strpos(':', $post);
$filter[] = strpos(';', $post);

if(isset($filter['0']))
{
$post = 'alert';
}
return $post;
}

//Should return "alert"
$Test1 = 'hello cc:';
$Test1 = Stop_Form_Injection($Test1, '15');
print "$Test1 . '<br>'";

//Should return "hello Joe"
$Test2 = 'hello Joe';
$Test2 = Stop_Form_Injection($Test2, '15');
print "$Test2" . '<br>';

Oct 25 '05 #1
3 3134
Help, I'm stuck! I've written the below function as part of my form data
filtering steps and for some reason It won't return the right value!


All of these lines:

$filter[] = strpos('to:', $post);

will add another array entry even if the function returns nothing, so
your end test is always true. Recode.

---
Steve

Oct 25 '05 #2
Hi,

I tried rewriting with this and still not working any tips?

(strpos('bcc:', $post) === false) ? $filter[] = false: $filter[] = true;

if($filter[0] === true)
{
$post = 'alert';
}

return $post;
Thanks Tobierre
"Tobierre" <No******@hotmail.com> wrote in message
news:11*************@corp.supernews.com...
Hi all,

Help, I'm stuck! I've written the below function as part of my form data
filtering steps and for some reason It won't return the right value!

Can someone take a little look and tell me if you can spot any errors?

regards Tobierre

PHP Code:
function Stop_Form_Injection($post, $length)
{
$post = strtolower($post); //change input to lower case for search
purposes

//Check form input is allowable length
$length = strlen($post) - $length;
($length > 0) ? $filter[] = $length: $filter[] = false; //if form input
too long set false

$filter[] = strpos('to:', $post);
$filter[] = strpos('cc:', $post);
$filter[] = strpos('content-type:', $post);
$filter[] = strpos('\r', $post);
$filter[] = strpos('\n', $post);
$filter[] = strpos('charset=', $post);
$filter[] = strpos('mime-version:', $post);
$filter[] = strpos(',', $post);
$filter[] = strpos(':', $post);
$filter[] = strpos(';', $post);

if(isset($filter['0']))
{
$post = 'alert';
}
return $post;
}

//Should return "alert"
$Test1 = 'hello cc:';
$Test1 = Stop_Form_Injection($Test1, '15');
print "$Test1 . '<br>'";

//Should return "hello Joe"
$Test2 = 'hello Joe';
$Test2 = Stop_Form_Injection($Test2, '15');
print "$Test2" . '<br>';

Oct 25 '05 #3
I tried rewriting with this and still not working any tips?


Look up the arguments for <http://www.php.net/strpos>.

(Maybe the people arguing over in the IDE thread should look at this)

---
Steve

Oct 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
11
by: brian.newman | last post by:
I'm trying to use a layer inside a form to hide/reveal a part of the form, but my code doesn't seem to be working and I need some help debugging it. I'm not getting an error which has made it...
6
by: Rabel | last post by:
I have a shopping cart that I am having a few problems with. I am mostly a flash developer with basic if not little javascript knowledge, I need for my checkout to have a checkbox that if clicked...
1
by: nate axtell | last post by:
In VB .Net I made a custom CheckBox column style (for the Datagrid control) that maps to two DataTable columns , one it uses for the Checked status and the other it uses for the Enabled status. I am...
3
by: Richard Ryerson | last post by:
I have a general DataGridComboBoxColumn that I built using the Example in the .NET 2003 Combined Collection help file (that was a data time picker). I am able to assign a data source and display...
2
by: cbjewelz | last post by:
Hey all. So I'm having problems with cross browser alignments. I'm looking at Safari and Mozilla Firefox. I develop in Safari and so it looks perfect there however in Firefox my vertical...
2
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.