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




How Can Arrays Be Dynamic With User And Administrative Input.


Can someone please show me how by examples - how scalar and associatie arrays can be dynamic with the user and administrative imput.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Php/sql Question - How To Build A Dynamic Query Statement Based On User Input
I need to build a query based on what the user checks in the form. For
example, if the user does not check certain fields, I don' tneed to use
those in the query statement.

Arrays And Input Controls
I have a problem with a form vhere i wanna put some controls in an array to be able to read the values easy... but it dosen't work . PHP Code:

Form Input Into Arrays?
When passing form inputs to another php page, I know that a form field named field1 will pass the value to the next page in a variable named $field1.

However, is it possible to pass the field directly into an array? I ask this, because my forms are generated dynamically, and each form field is numbered - so I would like to pass the values into the appropriately numbered slot in the array for the next page.

Dynamic Multiple Input Processing
I am creating a simple "or so I thought" php/mysql survey.
There are 3 types of Surveys, with different questions. 1 for Clients,
1 for Employees, 1 for Peers.
Questions for each survey are created, editable, removable, and drag/
drop sortable.
Options to these questions are dynamic themselves.

Basically, everything works except when I try to Insert the data into
the answers table.

The one question I'm looking for is how would one process the data
based on the respective question_id's?
Sending it to another page would require an excessive amount of _POST
variables, and like i said before, there are different questions for
each survey.

or would this work? (it doesn't seem to process)
if($submit){
for($i=$start; $i<=$end; $i++){
$query[$i] = "INSERT INTO answer(ansresult, ansdesc, idquestion,
idsurvey) VALUES('q_$i','exp_$i','$idquestion','$surveyType' )";
$result[$i]= mysql_query($query[$i]);
if($result[$i]){$success++;}
}

$msg = sprintf("Success: %d, Questions: %d",$success,$end-$start);
echo($msg);
}

User Input...
I have a form with a field that expects user to input HTML tags. I know I have to use htmlspecialchars for that input but what if the user inputs PHP code? I've looked at the help file and I can only find strip_tags which removes both PHP and HTML tags.

If a user wants to crash/corrupt/hack into your site by entering PHP code, what kind of things can he type? Must he include PHP tags to work? If he must use PHP tags, I could just write a function to remove only the PHP tags and not the HTML tags.

User Input?
Is there a way to get user input from a php script that doesn't have to do
with html? I would like to ask the user(me) to input a directory(preferably
in a gui way such as a folder selection dialog) to do some work with. Is
this possible when running the script directly on my comp(not off a
server(remote or local))?

The script is a management thing that I'd like to create to help generate
some html code. Essentially I want it to scan a dir(but don't want to hard
code it) and have it generate a list of links for the files in that
dir(which are images). Maybe even asking for a description for each.

Even if it was a little shell program to change the directory(sorta like
dos) would be much better than having to enter in the directory name by
hand.

Php User Input
When running PHP as a binary, is there a way to ask for user input?

Dynamic Arrays
People come to my site, they choose the name of a car from a database. I want the name of the car to go into an array. I want to put it in an array and not just as a single variable because i want them to have the option of coming back to the page and choose the name of another car. They can have as many names of cars as they like. To make sure i retain the values of the array, i will put them in a session variable.

My question is how do i generate the dynamic array? When people come back to the page with the values of the array in the session variable will that cause a problem?

Verifying User Input
I want to be able to search through a string that gets filled into my form. Make sure there are no quotes, semicolons and that kind of thing, that will mess up my database query. PHP Code:

What To Strip From User Input:
I recently suffered massive bot attacks against my contact page.
Someone sent me over 350 e-mails from my form in less than a couple of
hours. As this form only sends e-mail to an address dedicated for
this purpose, this isn't more than an inconvenience. In re-writing it,
I decided to write better stripslash and strip_tags functions of my
own. I have the function stripping out left and right angle brackets,
and forward and back slashes. I replace these with blanks (I am the
only one that views these e-mails and I think I can figure out what
was meant). That should break most script and malicious html tags.

What else should I watch for and strip? I thought it might be wise to
replace "=" signs with blanks. Should I worry about words like
"query" or "fopen"?

Part of my solution to preventing bot attacks against my form is to
force manual input by varying the name="" values. I have eighteen
different possibilities for each field on the form. I choose which to
use randomly. I check each possibility when processing to see if it
is set and send posters to a 404 page if they post to the wrong or all
possible variables. I also include a random string of 5 digits as an
authorization code in a hidden field. I use mysql database to let the
processing page know what variables and authorization code to expect,
associated with the poster's ip. Use the wrong authorization code and
you go to the 404 page. If your ip doesn't show up on in the
database, you get a "404 page not found." I delete records from the
database after processing, including old, unused entries where someone
left without completely filling out the form. Does anyone see any
reason that won't work to thwart the bots?

User Input Validation
I am intending to make a form on a page, on pushing submit the forms gets posted  onto itself so that it checks for empty fields and prompts user to get all fields filled, BUT the filled value should stay, I did this easily on ASP, but could not figure out in PHP. Code:

User Input Filtering
I have a comments system. In this comment system, people can enter certain strings, and it will break my page layout. Such as repeated characters with no spaces. It will just blow the table way out of proportion and completely ruin my layout. How can I break their input up if such a thing happens? Also, how can you number an array of data that is being withdrawn from the database DESC? Such as..

Quote1. itemnumber1
2. itemnumber2
3. itemnumber3
4. itemnumber4

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?

Filtering User Input...
I want to take text that a user inputs and store it into a variable.  That's the easy part.
I have and array of 30 elements that I want to store the inputted text into.

So.. here's an example...
- I want a user to enter text.
- I'll store it into a variable like $inputText.
- I want to split the text from $inputText into 30 equal sections and store each section into an element in the variable.
- I don't care if the words get separated during the filter, as long as the whitespaces stay where they are.

Could anyone give me some tips to help me get started or point me towards a tutorial or something?

Dynamic Multidimensional Arrays
I am having trouble properly setting a dynamic variable that should be part of an array. Code:

Security With User Input And Sessions
I have two sort of related questions, if anyone would be so kind as to answer:

1. When I do an form for input (into a database) that is used for subsequently displaying on a web page, is there a function written to parse out all dodgy stuff, like putting HTML tags that could break the page, or filter out SQL that could corrupt or invalidate the entry or is there a regular expression that someone has already done to cover all areas?

2. If I am displaying data from a database and using sessions and the like, should I be putting something like this in my code (I found it in the php manual):

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0

Cleaning Up User Form Input In Php
Does anyone please know why when trying to clear up user input that has been entered into a form, php only clears up most of it and not all?

For example, using stripslashes to remove all slashes from a variable after a user has submitted quotation marks ("") into a form.

The quotation marks cause the variable being parsed to contain slashes.

e.g. a user enters """""" into a form , the variable returned to php becomes """""

So if I only wanted the quotation marks, I thought the stripslashes function would achieve this.
However, it only removes 3 of the 5 slashes leaving 2 unwanted slashes behind.

Calling A Function Through User Input.
So heres yet another question to a problem where I would have no idea
where to look for the answer for so I turn to you :)

Say my sites administrator wants to write a news update or blog or
whatever. Something like this

"Added a new gallery from my trip to Phuket, enjoy:
[GID=24]
If you liked it tell me."

I want the [GID=24] to get replaced by my galery loading function
(very nifty and handy) so it would turn into something like this

echo "Added a new gallery from my trip to Phuket, enjoy:
".galery($GID)."
If you liked it tell me.";

I chose this [GID=24] because it is similar to burning board code. I
would also like to include a command like [PID=45] witch would run my
picture function.

Cleaning User Input, Is This Safe Enough?
I've written a small function that cleans up all user input before entering it to the DB. I'm wondering, is this sufficient or am I missing someting?

function clean_text($text) {

$text = str_replace("<", "&lt;", $text);
$text = str_replace(">", "&gt;", $text);
$text = strip_tags($text);
$text = htmlspecialchars($text, ENT_NOQUOTES);
$text = mysql_real_escape_string($text);

return $text;
}

Dynamic Variabel Names In Arrays
I have a php script that makes multiple sql query's that results multiple datasets that I will use in a graph. Its set up something like this.

for($i=0; $i<$n; $i++){
sql query runs here n times and produce each time a dataset that looks like.

2007-10-17    3
2007-10-18    4
2007-10-19    2

I want to put each dataset in an Array with diferent name.
I manage to put on dataset it in one array

$ydata[] = $row[1];
$xdata[] = $row[0];
}

but I need one array of every dataset with names that I can recognize outside the loop, for eks a dynamic variabel name that consist of $i and some other name. like $i.$xdata[], but I cant make this work.

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:

How To Get User Input For A Variable Without Using Forms Or Tables
I have created forms and taken user input from the forms into php variables. When validating the fields, if i find my conditions not satisfied on the php variable, i ignore the database connectivity and display error message and having the user to go back to the page and correct the error.

Is there a way i can correct the error without going back to the page, and getting the particular user input without having to create another form or table for input into the php variable.

How Do You Do TCL Exec Command On PHP Script That Uses User Input?
The TCL command I am using will do a command-line action on a PHP
script:

set cannotRunPHP [catch {
eval "exec php -q $root/scripts/info/php/info.php"
} errMsg]

I have to do it this way as both the TCL script and the PHP script run
as CLI. However, "info.php" requires user input to run; this causes
the TCL script calling the PHP script to hose up and die.

Is there a way I can do this so that the TCL script can call the PHP
script without any problems? Is there an alternate way of calling the
PHP script other than using exec were that to solve this issue?



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.

Unable To Insert User Input Into Ms Sql Database.
i have tried to insert user input into ms sql database but still unable to do so. my code has no errors in it. its just that the user input cannot be submitted into the ms sql database. Code:

What To Use In PHP To Make User Input Safe For MySQL Query?
I believe that you want to escape certain characters in a query, like quotes, backslash, semi-colon, etc. Is there a function in PHP to do all this for you and make the string safe to use as a query string?

User Local Time Diplay In Input Field
I'm wondering how can I have the local time of a user into a input field, it might sound or be stupid but even after my search I couldn't find a code si9mple enough, without any bla bla which each not my need.

Dynamically Creating URLS Based On User Input !
I am looking to create pages on the fly or dynamically based on user input. For example if i have www.example.com and they visit this and enter 'bob' in a textfield and press submit they create www.example.com/bob.html . How would I go about this ? I am guessing I need to create a folder when submit is pressed in my website directory ?

Cleaning User Input (Removing HTML/stripping Slashes Etc...)
How can I remove HTML and add slashes to a variable?

I know I can add slashes with addslashes($var); but I need to know how to remove all HTML at the same time. Also - Are there any other characters I should strip from the variable (it will be stored in a database and displayed on a web page).

Use Cookies To Save Info On What The User Enter Last Time In A Input?
I am having some trouble looking for a good tutorial on cookies and how to have them save what you last time entered in the form. So how can I do this so users don't have to renter everything the next time they try to post something on my site?

Dynamic Image For User
I'm trying to create a user bar relating energy or life/hp which changes depending on their actions on the site im making.

Thing is though i don't want to make like 1500 images of the exp being 5% then another image for the 10% etc. It seems a bit tedious. Is there a way i can fill a red bar or what ever colour by changing variables that doesn't require tons of .gif files ?

Caching Dynamic Pages Dependant On User Status
I am new to caching dynamic pages. All I knew was how to avoid caching.

My dynamic pages have on top of them an html header which shows the status of the user logged/not logged.

I would like to cache the pages and force re-cache if there is a change in the user's status.

I guess the must-revalidate has to be always present. I use a last modified date which comes form my database. I think Cache-Control: must-revalidate depends on the last modified date... am I right?

Should I change that modified date to the time the user logs off or on?

Is it ethical checking the user agent for bots? When dealing
with bots should use the real last modified date.

Challenging The User With A Dynamic GIF To Ensure Theyre Human
On some sites there is an image that is dynamically generated at page load,
which simply has a few random characters like "a5J7" printed on it (which
change with each page refresh), and the user must enter in those characters
they see in a textbox as if it was a password. This allows the website to
confirm that the visitor is a human, and not just an automated script.

Does anyone know how (if?) this can be done with PHP? my Googling wasnt very
fruitful :(

Creating Dynamic Hyperlinks With User Id's In Php Query
Im dabbling with PHP and trying to write a new search.php file to scan for specic users in my dating website and then display the users along with individual links to their profile.

$profile = $row["id"];       -- this field takes profile ID from mysql database
The profile field pulls in an ID field from a mysql database for each record. I need to integrate this fields value into the hyperlink when the results are returned so it has a list of all users each with an individual hyperlink to their profile. Then users can click and access the profile of a specific user. Code:

Comparing User Input Values In A Form With Database Values
I want to compare user input values in a form with my database.
Basically I want to check whether the user exits in my database.
What mysql command can do that?

$_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.

PHPmyadmin Access Denied For User 'user'@'localhost'
WinMe machine as server, with Apache 2 installed and working PHP4 installed and working ( had PHP 5.05 installed and working, but i couldnt get the mysql extensions to load - phpinfo() didnt list mysql :(, so i installed PHP4, which now lists mysql when i run phpinfo). MYSQL 4.1 installed and working. I dont know the console commands too well, but i know its working ok, cos I have used a few simple DOS prompt commands to check its alive and I can connect to the database using MyODBC frontend/driver 3.51 and also using Navicat 2004.

When i try to connect to the database via PHPmyadmin from another network PC I have an error:

#1045 - Access denied for user 'user'@'localhost' (using password: YES)

I have played around alot with different settings in the config.inc.php file.... nothing seems to work.

This almost appears to be a simple login problem ( probably is too), but I can access the database locally from the Winme machine with the username and password that wont work over the network!

I have tried not using 'localhost' as the host name but the IP address of the Winme PC but I get this error:

#1130 - Host 'MYSERVERNAME' is not allowed to connect to this MySQL server

Notice: Use Of Undefined Constant User - Assumed 'user'
I have a script for a shopsystem on a Linux. There it works fine.
But when I try to run it on my Windows machine, PHP says things like

Notice: Use of undefined constant dbname - assumed 'dbname' in
c:apachehtdocsaposhop estshopclassesxxx.clas s.php on line 77

On Windows I run PHP 4.3.2
On Linux runs PHP 4.3.1

Authenticating User Common User Names
I want to create a password protected page with PHP and Mysql. I have 2 groups User and Admin. The respective groups have a common user/password. The user/password are stored in a database. I want to authenticate the user through a login form and not through a pop-up ($PHP_AUTH_USER) way.

What I want is, if a user logs in and he moves from one page to another, he should not be asked for validity again. Is this possible only with scripting (without session and $PHP_AUTH...). If yes - how do I keep track of an authorised user and unauthorised user, so that he should not be validated again. Does setting the user variable to global in all the pages do the trick.?

User Authentication And PHP Saving As Specific User.
the users of my server had to upload their pages by sftp and only the user who uploaded a page was able to edit itafterwards.

I've been asked to make a secure way for users to log on through the web and edit their pages online. However, although using .htaccess to authenticate users, the script saves as user 'nobody' and is not able to edit pages previously uploaded (and saved as user 'john_doe'). What I am trying to do is make the script save using the same username as the user used to log on.

Fill Fields When User Selects User From DB
I have a field with a selectbox which contains a list of client names and several other fields which display information from the DB.

I need to be able to make the fields change to the appropriate information when a user is selected from the select box. Can anybody please give me an example of a bit of code that will do this?

Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried.

This is what my array looks like:
array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" }

This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s).

I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation).

I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:

Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for.

so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase.

say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.

How Do Remove A User From MySQL.user?
How do you permanently remove a user from the MySQL database.

Delete from MySQL.user where user="Unwanted User";

just seems to ignored.

How To Use Php:// Input?
I tried using php://input in the following script but nothing is output
when I run it:

<form action="test.php" method="post">
<input type="text" value="demo" />
<input type="submit" />
</form>
<?php
$fp = fopen('php://input','r');
while (!feof($fp))
echo fgets($fp);
fclose($fp);
?>

Any ideas as to what's being done wrong?

Input Box Query
Hi,

I am using the following code to check whether a user wants to delete something

function confirm_entry(loca, ques){
input_box=confirm(ques);
if (input_box==true){
document.location = loca;
}
}

how can i modify this so that if the user clicks cancel they stay on that page?

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?

Validating Input
What is the most efficient way to validate an input to conform to your
needs?

I need to make sure an input is a contiguous string with only printable
characters (english alphabet+numbers only) and no whitespace or
punctuation marks.

Filtering Out Bad Input
I am currently building a website, with a built in news and comment, so far i know have been able to filter out thing such as swear words, however is it possible to filter of say f someone held down the ===================================================== ============= key

Is there a way to prevent this or will i have to have some sort of statement that counts how many times the = or other char is grouped together?


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