Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Checking Input Text?


I wondered if this script seemed correct? The user should enter a
userid and password in two text fields, and then pass these values to
the method login_user.

Could I ask, is there any approach to, once the user clicks the submit
button to test the userid and password has been entered, and the text
fields are not empty.

<?php

function login_form(){
?>
<html>
<head>
<title></title>
</head>

<body>

<div align="center">
<form method="post">
<table border="1">
<tr>
<th align="right">E-mail</th>
<td nowrap>
<input name="userid" size="25">
</td>
</tr>
<tr>
<th align="right">Password</th>
<td nowrap>
<input name="password" size="25">
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="submit" value="Login">
</td>
</tr>
</table>
</form>
<div>
</body>
</html>
<?php
}

login_form();
$user_info = login_user($_POST['userid'], $_POST['password'];
?>




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Checking Input Of An Url Or Ip?
i do use the following code:

Code:
if ($siteurl == "") {
$badreg = true;
$valid_url = false;
echo "<span class='main'><font color='#C10000'><b>Error:</b></font> Please check your url.<br>
";
} else {
$valid_url = true;
$siteurl = ereg_replace("http://", "", $siteurl);
list($domain, $file) = explode("/", $siteurl, 2);
$siteurl = "http://" . $domain . "/" . $file;
}

Any idea how i could extend the " if ($siteurl == "") { " for checking for valid domain names and ip-addresses?

Checking Form Input
Well i've eventually manage to get a comments system working on my site, adding information etc. however i want to add a few saftey precausions.

I.e prevent use of HTML commands been enterend into a comment or holding down a single key, that can often lead to tables been pushed out of size, thus messing up the site. i have been using a function that strips out swear words, this works fine, I included an option to remove HTML etc... using PHP Code:

Checking User Input
I want to check to see if there's only letters and numbers in a field, how would I go about doing this?

Form Input Error Checking
Have a form field being inserted, needs to only allow an integer value through. Which function do I want to use to check the passed var to see if there are any non-integer values present? PHP Code:

Checking For Valid Date Input
If a date is entered in a form with MMDDYY, how do I check if this input field is a valid date. Is there a php function to do this?

Checking User Input With Eregi Function
The function below (ExpressionTest.php) is for checking user input. The function is supposed to permit only alphabetical characters, the apostrophe ('), and the dash (-) for the "FirstName" variable. For some reason the script below will permit the dash to be used but gives the message "Please enter a valid first name." message when the FirstName variable includes an apostrophe.

I have tried switching places for the dash and the apostrophe. But if I place the apostrophe first in the string and the dash second in the string I still get the same message. PHP Code:

PHP Input Checking - Checks For Illegal Characters
I have a HTML form where the user can type in certain values, but I
only want them to able able to submit integers (0-9). I post to a PHP
page with the following "snippit" of code (all the variables have been
properly assigned):

// Checks for illegal chars
$illegal_chars = array("`", "~", "!", "@", "#", "$", "%", "^", "&",
"*", "(", ")", "-", "_", "=", "+", "q", "w", "e", "r", "t", "y", "u",
"i", "o", "p", "[", "{", "]", "}", "", "|", "a", "s", "d", "f", "g",
"h", "j", "k", "l", ";", ":", "'", """, "z", "x", "c", "v", "b", "n",
"m", ",", "<", ".", ">", "/", "?");
foreach ($illegal_chars as $value) {
if (stripos($db_mysql, $value)) { $pass1 = "f"; }
elseif (stripos($db_postgre, $value)) { $pass2 = "f"; }
elseif (stripos($db_oracle, $value)) { $pass3 = "f"; }
elseif (stripos($email_basic, $value)) { $pass4 = "f"; }
elseif (stripos($email_exchange, $value)) { $pass5 = "f"; }
elseif (stripos($ftp_users, $value)) { $pass6 = "f"; }
elseif (stripos($domain_subdomains, $value)) { $pass7 = "f"; }
else {}
}

The code will not work, and I can't see why. The variables $pass1-pass7
aren't set after the foreach() loop, no matter what is in the input!

When To Clean Input Text
I was wondering what people do with text provided by the user in a
form. Some cleaning needs to be done at some stage if you are going to
be putting it in a database or displaying it etc. But when is the time
to do that?

Do you clean it as soon as you get it?
Do you pass around the original text and clean it when you use it?

What about magic slashes? You need to addslashes before using in a db
statement, but you need to strip them when displaying. When do you do
that?

Text Area Input Box With PHP
I have a text area box on one page. PHP sets the information that is inputted into the text area into a variable. When I print this info to the screen via echo, it does't have the line retain the formatting that the user had in the text area. It has no line breaks, it runs everything together.

Input Text Issues
Whenever I receive input from an HTML text field or and HTML text area
with " or ' meaning double or singe quotes into a php variable and
then print or echo it back out to the user in html I get these
characters accompanies by a . Why is this and how can I get rid of it.

$submitform->body=@$_POST['body']; <<<< there are no in the input.

print("body - ".$submitform->body."<br>"); <<<< but here there will
be slashes for all ' or " .

Text Input With Links, Etc..
I hope you can give me a few pointers on this issue.

I'd like visitors to my website to be able to enter text to be viewed on the
site - a bit like a bulletin board or forum. I can do this for regular text
easily by simply populating a 'TEXT' field within my MySQL database and
grabbing it back when rendering the site using PHP. However, I'd also like
visitors to be able to put in URL links or email items that can be clicked.
How would I go about doing this?.I've seen this sort of thing on forums
where words can be selected and a URL applied, but I have no idea how to do
this and how this information (ie. the link and the associated text) would
be stored in the database field(s).
Any ideas?. Are there any PHP examples available for this sort of thing?.

Input SQL Data Through Text Box And Get Nothing?
I want to add SQL command through a textbox in the form using post
method,but when i execute the following file, nothing is added to the
database.
I can add
$sqlol = "update acc_account
set user_name='k'
where accountid=1";
to the database if it was added to the file but when i use $result =
mysql_query($sql); which execute the query, it get nothing. However,
the $sql statement do print out on the screen using print.

<?php
$conn=mysql_connect('localhost', 'shytr8');

if(!$conn)
{print "Error- Could not connect to MYSQL";
exit;}

$er=mysql_select_db("test");

if(!$er){
print "Error- Could not create er";
$query = "CREATE DATABASE test";
mysql_query($query);}

$sql=$_POST[SQLcommand];
$result = mysql_query($sql);
?>

Spaces In <input Text> Boxes.
When I submit a form where a user has typed a space into the input box, then check that value in the action .php file, only the text before the first space is displayed. How can I get all of the text sent?

eg

Code:
<form name="form2" method="post" action="temp.php">
<input type="text" name="name">
<input type="submit" name="Submit" value="Submit">
</form>

Then in temp.php
Code:
echo "Username = $name";

If the user enters "Greg Bennet" into the text field, I get back "Username = Greg".

Double Quotes In Text Input
I accept text, add_slashes, and store it in my MySQL DB. When I display
the text, I normally strip_slashes and also strip_tags. This all works
excepts for a field with double quotes. e.g.

"My Book's Title" is very simple

When I display this field, it is totally blank. What's the solution?

Wiki Style Text Input
I have a text file called test.txt which is I am trying to get to load
into a webpage. This is simple enough, but I am trying to make it so
that it recognises certain formatting, similar to how wikipedia pages
work.

so, my text file contains ONLY the following:

This is /just/ some test text *to see* if the PHP works
and to /*evaluate*/ what it actually does

The intention is that /just/ will show as italic, *to see* will show as
bold and /*evaluate*/ will show as bold italic.

Creating the text inside the page works fine.

<?php
$s = 'hello. /this/ works *bolding* works. /*Both work*/!'
$search = array ( '@/(.*?)/@si',
'@*(.*?)*@si');
$replace = array ( '<i>1</i>',
'<b>1</b>');
echo preg_replace($search, $replace, $s);
?>

However when I try and read from a text file using

$s = file('./wiki.txt');
$search = array ( '@/(.*?)/@si',
'@*(.*?)*@si');
$replace = array ( '<i>1</i>',
'<b>1</b>');
echo preg_replace($search, $replace, $s);
?>

All that is shown is the single word 'Array'. This confuses me a lot as

<?
$s = file('./test.txt');
print_r($s);
?>

shows that the text is being read into the page
Array ( [0] => This is /just/ some test text *to see* if the PHP works
[1] => and to /*evaluate*/ what it actually does )

How Can I Insert A Deafult Value In An Input Text Box?
for example if I have a box where you should put a date how do I keep
today date inside that box as default?

Simple Looped Text Input
I'm trying to build a website with a simple text input option. After the input, the input is checked and acted upon accordingly. This is followed by a new input line.

For example:
> input: test

"test" is not known to me

> input: _

So far, I've been trying things with the "do-while" loop (see code below), but so far, all I seem to get is a fixed input box and the "respons" being displayed below it. Code:

How Can I Print Out Multiple Text Input Boxes?
How Can I Print Out Multiple Text Input Boxes. The function below prints out three text boxes. The code below is static, cannot accept user input, and therefore cannot be changed. What I need to do is write a function or maybe a class that can accept user input and print or echo a different number of text boxes, depending on the user input.

The name variable for each of the textboxes needs to have a different name. For example, the name for the first text box would be something like "name=textfield1", the second would be "name=textfield2", and so forth. PHP Code:

Returning Text Input Type As Array
I'd like to make all the text inputs in this form to be part of an array. The reasoning is that the form is built dynamically so there are times when there are 4 inputs while other times it's 12. When the form is submitted I need those inputs to be error checked and such.

Updating Text File With Textarea Input
i am creating an admin page for a person to update a page of their website through a web browser. the problem that i am having is the formatting of the inputted data into the textarea box. when it is displayed, all the returns and breaks are removed and the data is all in one line. i have been experimenting with nl2br() but i am not sure where to put it.

Text Input Of Date And Timestamp Fields
I'm working on a PHP frontend for a PostgreSQL db and I'm looking for the
best way to create date or timestamp inputs. Let's take a date in the
format yyyy-mm-dd as an example. This is too error prone, I know my users
will do it wrong

<input type="text" name="fieldname">

Right now I'm thinking about something like this:

<input type="text" size="4" name="y_fieldname">-
<input type="text" size="2" name="m_fieldname">-
<input type="text" size="2" name="d_fieldname">

but this is IMO a very ugly solution, because after the SUBMIT I have to
glue all the parts together before inserting the values into the db.
Something like this:

<input type="text" format="yyyy-mm-dd" name="fieldname">

Displaying Text Fields On User Input
How would I echo a particular amount of text fields depending on how many the user selects from a drop down menu that I have already created. For example say the user selects 4 or whatever other number from a drop down menu how would I echo 4 or whatever the amount of text fields for a user to input text into? An example would be an airline website were you select how many people are travelling and then it echo fields for those people to enter their names.

Tag In Smarty Which Enables Us To Get The Input Type=text
Is there any tag in Smarty which enables us to get the input type=text alongwith the value filled from a variable?

i.e. a tag such as html_text such that I get input type=text alongwith value?

Text Input Box Automatically Escapes Quotation Mark
Text Input Box Automatically Escapes Quotation Mark

The text input box below works fine with text. However, when a single or double quotation mark (i.e. ' or ") is entered the code below outputs an escape mark. For example, if the word DevShed is entered into the text box then executed the code simply outputs the word DevShed. But if the word DevShed is put in quotation marks, like so "DevShed", and executed the code outputs the following: "DevShed".

My question is this: How can I keep the PHP code from automatically escaping quotation marks when the form text input box is executed?

Clearing The Input Text Field After Submiting The Form To A New Page
I have a page with a form with an input text field ... and when a user types his/hers ID ... and submits the form - his/hers page opens in a NEW window .... but the value (ID) that was written in the original window remains.

I want to make sure that the form input field on the original page becomes "invisible" - by refreshing/reloading the original page or just by clearing the input form after submission.

For now I have put in a meta refresh tag in the head of the html file ... but that is not the solution ... becouse I only need a one time refresh/reload of the page ... and this is to happen right after the input text value is being submitted.

Detecting URL's And Html Tags In Text, Input From Form
Is it possible to check text and set a PHP variable if someone inputs links, <h1></h1> ect. and other html tags when filling out your form mail or guestbooks?

$_POST Behavior From Input=submit Vs Input-type=button
I have been trying to solve an annoying behavior with PHP (I think).
Maybe some of you have encountered the same and have some ideas.

I have an html form and I use an <input type="button"> element with
the onClick event that calls a javascript funtion. Once the script's
content has been processed, I execute the form.submit() directive.

I would like to combine the html form and the PHP script into one, and
use action="<?php echo($PHP_SELF) ?>".

When the html form has <input type="button" name="theButton"
value="thisisthetrigger" onclick="doThis(this.form)">but PHP cannot
'read' the value of $_POST["theButton"] after form.submit().

If I substitute the <input type="button"> for <input type="submit">
then PHP reads the value just fine. Some may argue to just use the
latter option, but that will cost me a trip back to the server to
basically do a lot of validation that can be very easily accomplished
on the client side.

Quickly Adding Text To A Mysql Text Field That Is NOT Empty
Is there a way to insert text into a mysql text field that already has
text into it; without having first to extract the existing data and
append the new text to that string variable and then insert the new
string.

Basically i'm looking for a way to do it with a single query not 2 (one
being a select to gather existing data).

Gaining Access To How MySql Parses Text For Full Text
I want to gain access to the function or process MySql uses to parse words and phrases for Full Text searching. Here is an example.

If the user inputs...

Milan in history

MySql will search for milan, history, and milan history. Is there a way to extract just the combination of terms MySql uses to search the db without the stop words? Stop words are automatically eliminated from the search request unless the user encloses a phrase in quotes.

What I am trying to do is develop a script to highlight found search terms and phrases. I can explode a phrase into single words but if I do that the stop words would be included in the array. If there is some way of getting into the parsed words or phrases MySql Full Text actually uses to search, I can use each of those combinations as a keyword in my highlighting script.

This request is about searching for the code or any code related to the questions involved.

Text Area Not Accepting Large Amounts Of Text
I have a form where teachers enter homework assignments and they are then stored in a MYSQL database and retrieved elsewhere.

I have been using "get" with the form. The code is simple:

<textarea name="array[assignment]" cols="60" rows="10" id="array[assignment]"></textarea>

It does allow post of 100 words, etc. Stuff that teachers normally submit.

What's happening is that it won't allow very large posts (over 300 words maybe? ) Not sure what the cut off is. When you press submit it won't go, or there is an error where it won't submit.

Is there a limit for text fields? Since the fields scroll, I didn't think that having only 60 rows was any type of real limit, I though you could put in as much as needed. But then all of it ends up in the address bar, so there must be a limit of some sort.

Imagettftext() Gives Grainy Text When Writing Aliased Text
I'm using a bundled version of GD: 2.0.23 compatible. When using the
function imagettftext() with a negative color to get a aliased text,
the text gets grainy. What could be wrong? I've tried several ttf
fonts, with the same result.

Read And Display Japanese Text From Text File
I posted a question regarding reading japanese
text from a text file.

Well, since I solved the problem, I thought I'd post my solution for
the benefit of other people with the same problem.

The plan was to make a script to read and display japanese text. I
will use it for making a japanese proverb script and for a japanese
language study script.

Method :

I wrote a simple kanji text file (saved with UTF-8 encoding)
I wrote a simple PHP script to display the file contents (saved with
UTF-8
encoding)
I specified the content-type header for the HTML page :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

*** All files have the same encoding. ***

UTF-8 supports japanese characters.

and it works!

this is my PHP (and HTML) script :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP : Japanese Text File Read : Exercise 1</title>
</head>
<body>

<?php

$filename="japanese.txt";
//open file
$fp = fopen($filename,'r');

//loop through each line in the file
while($line=fgets($fp))
{
//output current text file line
print $line."<br>";
}
//close file handle
fclose($fp);

?>

</body>
</html>

I know it's a very simple script, for testing purposes only. It
displays the contents of the japanese text file line by line.

The key was to save all files in the same encoding (I used UTF-8) and
to specify the encoding / charset in the HTML header (<meta
http-equiv="Content-Type" content="text/html; charset=utf-8">)

Append Text At End Of Existing Text On Same Line
I'm working on a part of my web site that uploads images, then writes the name of the image to a text file. The upload part works fine. The part that writes the name of the image to the text file works fine.

What I'm trying to do is, after all the files have been uploaded and all of the image names have been written to the WriteTo.txt file, append a written description of the picture at the end of the picture name. In other words, after a user uploads their pictures to the server I want to direct them to a page where they can label each of the pictures using a form. PHP Code:

Adding Text To Text Window With A Button
I have made an admin section of a site, What i want to do i have buttons under that have "BOLD" "center" and when clicked it adds <b></b> tags to the text area etc etc..

if the text area was called "message"

how would i going about coding the images / buttons to add the code?

PHP - Using Mail() And Unicode Text - Text Gets Disturbed
I have the following problem. On a website there's a (simple) feedback
form. This is used also by Polish visitors who (of course) type Polish
text using special characters.

However, when I receive the text in my mailbox, all special characters
have been turned into mess......

For example: "wspólprace" is turned into "współprace".

It seems PHP is handling the Unicode-8 strings quite well (when I
'echo' the strings on the site, I see the text correctly), until the
point that it is send by using mail().

Is this a server configuration issue? Or something else?

How can I get my text to remain in Unicode?

I have this problem both on my testserver (Apache 1.3.28, PHP 4.3.2 on
Windows XP) as on my providers server (Apache under Linux).

Remove Text Header In Text File
I have been having trouble removeing two header lines at the top of my txt file. You will see in my code the different things I have tried but with no luck. Below I posted my script and data. I am doing a few other things in my script as you will notice but this is the only thing I am having troble with. Code:

Parsing Text - Capture Text Between Two Tags
I want to have text in files, such as

{body}
{/body}

and then be able to open that file and grab all of the data inbetween those tags. I could open the file and go through it until I see the {body} tag and then store data until I reach {/body} but that is a bad way to do it.

Text Returned From DB Gets Cutoff When Placed In A Text Field
I have a string that contains an apostrophe or a quotation mark, stored in a DB. I can retrieve the data, and display it properly (for editing) in a textarea, but when I try to put the string in a text field, it get's cut off right before the questionable character.

For example:
$string_in_database = "John's car."

 -displays correctly here <textarea><?php print $string_in_database ?></textarea> and displays this - John's car.

 -gets cutoff here <input type='text' value=''<?php print $string_in_database ?>' /> and displays this -  John

I've tried adding slashes and stripping slashes and I just can't figure out what I need to do.

Keep Text In Text Boxes After Form Is Rewritten
I'm trying to make a form that does the following:

(1) the user answers a question by typing in a text box
(2) a response is then written below the form, saying whether the answer is right or wrong and, perhaps making a comment of some kind
(3) the user's answer remains visible in the original text box

I've managed to write some code that does the first two things, but despite many attempts and much searching for code examples, I've failed to find a way of getting the answer to reappear in the text box when the page is rewritten.

This is my code:

URL Checking?
how do you check if a browser came from a specific URL??

Checking For XSS ?
Does the check below ensure that the files are originating from my server,
i.e. to prevent or detect
any type of XSS ? Or is the HTTP_HOST easily spoofed ?

function test ($refer)
{
if (!stristr($refer, $_SERVER["HTTP_HOST"])) {
die();
} else {
}
}

test ($_SERVER["HTTP_HOST"]);

IP Checking
I have to do this for security measures on a script I am doing: To ensure the authenticity of the HTTP requests you should only accept requests from the following IP addresses: 80.87.132.0/26 (ie .0 -> .63) is there a simple way to do a range of IPs ie
IF $ipaddress == 80.87.132.* If not does anyone have a good function for this?

Checking %'s
Is there a built in function to check if a value is a certain % of a different value?

Like:
If($Value < 10% $value2)

sort of thing ?

Or do i have to work out the 10% first then check against that?

IP Checking
I have a rating system, and its supposed to let people vote only once but right now I can vote 50 times in a row if I want, and I dont know why its letting me vote multiple times, here is my code:

Replacing Text For Use In A Text Area...
I have a PHP page that allows a user to preview an email and then send it
if(s)he is happy with it.

Otherwise, they can click on an edit button and edit the text of the
message. The text is then shown in a textarea element.

While in situation A (the preview), a bit of formatting is useful (e.g
<BR>), all of this formatting is a nuisance in the textarea.

Basically, I would like to do the following:
a. replace <BR> with a line break for the textarea
b. get rid of double spaces and tabs before the text is loaded in the
textarea
c. put the <BR>s back in when the user is finished with editing the message.

Is there a way to do this?

Spell Checking
How can i spell check without including the aspell or pspell libraries ( can't include them because i'm on a virtual host ). I don't mind if its an external service. Spellchecker.net was great, expect now you have to pay for it.

Checking A Field
I've seen a couple of form generation and validation scripts.

Checking Mail
Is there any easy and quick way to check if a user got any/new mail with PHP? assuming that the user's mailbox is on the same system and the system is UNIX (Linux,BSD, etc.)

Checking If A Url Works
ok i need to check a url to make sure it works, and if it does, then
i want to print out "online", and if it returns 404 then i want to
print out "offline". how do i check if the url works or not?


Copyright © 2005-08 www.BigResource.com, All rights reserved