PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 10 votes, 4.50 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #16  
Old October 2nd, 2002, 06:16 AM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Corporal (100 - 500 Reputation Level)AlCapone User rank is Corporal (100 - 500 Reputation Level)AlCapone User rank is Corporal (100 - 500 Reputation Level)AlCapone User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 13
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
#32 Since I upgraded to 4.2 I get Undefined Variable errors. Why?
Not a bug - feature Those are not errors, those are warning for you, as programmer, so you keep track of which variables are used before being initialized or which ones are not being set.

If you want to fix this, edit you php.ini and set error_reporting = E_ALL & ~E_NOTICE Alternativly you could use error_reporting() run-time or php_value error_reporting "E_ALL & ~E_NOTICE" in .htaccess Although it might be a good idea to leave warnings while still in developing phase.
__________________
And you know I mean that.

Reply With Quote
  #17  
Old October 9th, 2002, 04:57 PM
4Life 4Life is offline
Please call me Joe ;)
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: the web
Posts: 244 4Life User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
#33 HELP! I need to remember my form values after submit!

I have seen a lot of posts around here lately on how to remember form values after the user hits "submit" [so that they can be corrected]. Well the method that I use is very simple: I store my form in a function, and then when I need to display it I just call that function. After a presses submit, I just display the form the submitted values in it. Easy as pie!

Here is an example (this is kinda long ):
PHP Code:
<?
# Save this as"form.php"
$val1 =$_POST['val1'];
$val2 =$_POST['val2'];
$action $_POST['action'];
if (
$action != 1) {
echo 
'Hi welcome to this form! Please be sure to fill it out <i>completely</i>!';
echo 
my_form();
}
else {

if (!isset(
$val1) or empty($val1)) {
echo 
'Oops! You forgot to enter $val1!';
echo 
my_form($val1='',$val2);
exit;
}

if (!isset(
$val2) or empty($val2)) {
echo 
'Oops! You forgot to enter $val2!';
echo 
my_form($val1,$val2='');
exit;
}

echo 
'Thank\\\'s for submitting Value 1 and Value 2. Here is the original form:';
echo 
my_form($val1,$val2);

}

function 
my_form($val1='',$val2='') {
$my_form_code = <<<EOC
<p>
<form method="post" action="form.php" name="my_form"> 
Value 1: <input type="Text" name="val1" size="45" value="$val1">
Value 2: <input type="Text" name="val2" size="45" value="$val2">
<input type="submit" name="submit" value="Submit">
</form>
EOC;
return 
$my_form_code;
}
# You can also add sessions to this.....
?>


Please note: This code is untested, but it should work!

Cheers,
Joe of 4Life
__________________
Cheers,
Joe of 4Life

Check out 4Life today!

Reply With Quote
  #18  
Old October 31st, 2002, 10:17 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,395 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 4 h 48 m 59 sec
Reputation Power: 255
How Do I Set Up Php As An Isapi Module?

#34 HOW DO I SET UP PHP AS AN ISAPI MODULE?!

See this interesting (and clear) explaination Configuring IIS to Use PHP


[Moderator's Note: The installation chapter of the manual details the exact same procedure]

#34bis HOW DO I SET UP PHP AND APACHE ON WINDOWS?!

See this document (link posted by delboy_trotter)

#34 Ammendment

Ready built WAMP (Windows, Apache, MySQL and PHP) packages can be found here:

http://hotscripts.com/PHP/Scripts_a...tallation_Kits/

#34c HOW DO I SET UP PHP INSIDE TOMCAT?!

This is how I did it Php and Tomcat

Reply With Quote
  #19  
Old October 31st, 2002, 07:28 PM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 9
#35 FORM FIELD VALIDATION
This is a function that can easily be cut and pasted into your code to validate form field data returned from a user.

Example of use:

field_validator("Email Address", $email, "email", 5, 255, 1);

parses the string contained in $email to make sure it is of type 'email', between 5 and 255 characters long, insisting the field is required. Any errors found are stored in the global array $messages.

Code:
function field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1) {
    # array for storing error messages
    global $messages;
	
	# first, if no data and field is not required, just return now:
	if(!$field_data && !$field_required){ return; }

	# initialize a flag variable - used to flag whether data is valid or not
	$field_ok=false;

	# a hash array of "types of data" pointing to "regexps" used to validate the data:
	$data_types=array(
		"email"=>"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$",
		"digit"=>"^[0-9]$",
		"number"=>"^[0-9]+$",
		"alpha"=>"^[a-zA-Z]+$",
		"alpha_space"=>"^[a-zA-Z ]+$",
		"alphanumeric"=>"^[a-zA-Z0-9]+$",
		"alphanumeric_space"=>"^[a-zA-Z0-9 ]+$",
		"string"=>""
    );
    
    # check for required fields
    if ($field_required && empty($field_data)) {
        $messages[] = "$field_descr is a required field.";
		return;
    }
    
	# if field type is a string, no need to check regexp:
	if ($field_type == "string") {
		$field_ok = true;
	} else {
		# Check the field data against the regexp pattern:
		$field_ok = ereg($data_types[$field_type], $field_data);		
	}
	
	# if field data is bad, add message:
	if (!$field_ok) {
		$messages[] = "Please enter a valid $field_descr.";
		return;
	}
	
	# field data min length checking:
	if ($field_ok && $min_length) {
		if (strlen($field_data) < $min_length) {
			$messages[] = "$field_descr is invalid, it should be at least $min_length character(s).";
			return;
		}
	}
	
	# field data max length checking:
	if ($field_ok && $max_length) {
		if (strlen($field_data) > $max_length) {
			$messages[] = "$field_descr is invalid, it should be less than $max_length characters.";
			return;
		}
	}
}


For a demo and more details check here:

http://validator.munk.nu/

Thanks go to the user raydenx who wrote the original function in this thread.

Reply With Quote
  #20  
Old November 11th, 2002, 10:17 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,360 Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 3 Weeks 6 Days 2 h 26 m 30 sec
Reputation Power: 1606
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Re: #30 How do i str_replace thats not case sensitive

Quote:
Originally posted by ape2man
#30 How do i str_replace thats not case sensitive

PHP Code:
/* Was submitted by jpenn : Senior Member */

function stri_replace$find$replace$string )
    {
    
$parts explodestrtolower($find), strtolower($string) );

    
$pos 0;

    foreach( 
$parts as $key=>$part )
        {
        
$parts$key ] = substr($string$posstrlen($part));
        
$pos += strlen($part) + strlen($find);
        }

    return( 
join$replace$parts ) );
}

echo 
stri_replace$find$replace$string ); 

FYI: It's considerably faster to just use preg_replace() and use "i" as a pattern modifier to make the search case insensitive.

$b = preg_replace("/this/i","that",$string);

---John Holmes...

Reply With Quote
  #21  
Old December 8th, 2002, 02:36 PM
Fat_N_Furry's Avatar
Fat_N_Furry Fat_N_Furry is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 3 Fat_N_Furry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by SepodatiCreations
Compared as text, they come in this order:
1
10
100
2
20
200
3
30
300


I think that's because PHP treats it like a floating point integer whre the first digit is the whole number and the rest of them are places after an invisible decimal point. Am I correct? Sorry if someone has already posted this. I didn't read the entire thread.


Furry

Reply With Quote
  #22  
Old January 8th, 2003, 03:37 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,395 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 4 h 48 m 59 sec
Reputation Power: 255
#36 How to schedule PHP scripts

Since this is a common question in the forums, I'm writing down my solution for this in the hope it helps others.
It has been developed on Windows but it should provide hints to *nix users also.
It works for every version of php, not only CGI and on remote servers also.

1. Download and install CRON for Windows from http://www.kalab.com/freeware/ (there is a version that runs as a service)
2. Download various Unix utilities for Windows from http://unxutils.sourceforge.net/ and install (copy) WGET
3. Choose a working php script to be run, mine is something like:
PHP Code:
[SIZE=1]<?php
    mysql_connect
("host""username""password");
    
mysql_select_db("database");
    
$result mysql_query("SELECT * INTO OUTFILE \"c:/path_to_writeable_folder/result.txt\" FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY \"\n\" FROM users");
?>[/SIZE] 

4. Create a batch file like this (scheduler.bat):
C:\usr\local\wbin\wget.exe --spider --quiet http://host/path/file.php
(--spider means "don't download anything" and --quite means "no output")

5. Add an entry for it in crontab file, like:
# select into outfile every day at midnight
0 0 * * * C:\usr\local\wbin\scheduler.bat


6. CRONTAB and the log file for cron service are located in c:\WINNT\system32

Please PM me any suggestions/comments about this!

Reply With Quote
  #23  
Old January 8th, 2003, 04:13 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,360 Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate FolderFolding Points: 69546 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 3 Weeks 6 Days 2 h 26 m 30 sec
Reputation Power: 1606
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
#36 How to schedule PHP scripts (cont.)

If you're on Windows, you can also use the built in Task Scheduler program to run a command such as:

c:/php/php.exe -q c:/path/to/php/file.php

Which will run your script according to the schedule you choose. Every installation of PHP has an .exe file, even if it's installed as a module. Also, newer versions of PHP have the CLI version that can be used for this, too.

Another alternative would be to run iexplore.exe and call up your page, which would be similar to the wget/lynx method commonly used.

c:/winnt/iexplore.exe http://localhost/path/to/file.php

For this option, you'll want to check the box that says "End program after X minutes" so that IE will shutdown after so many minutes.

---John Holmes...

Reply With Quote
  #24  
Old February 3rd, 2003, 09:41 PM
TommyWillB's Avatar
TommyWillB TommyWillB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: ol' Gay S.F.
Posts: 94 TommyWillB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 39 sec
Reputation Power: 7
#36 works under MacOS X's Unix terminal too:
% open /Applications/Internet/Internet\ Explorer.app http://localhost/path/to/file.php
__________________
TommyWillB
Apple Power Mac G4 867mhz, 1GB RAM nVIDIA geforce 2 (TwinView) Apple Studio 17" flat screen + Compaq 17" 2x60GB ATA drives
jeffntom.com hosted on Mac OS X 10.3.4 / Apache 1.3.29 / PHP 4.3.2

Reply With Quote
  #25  
Old February 15th, 2003, 12:55 PM
Kaklz Kaklz is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Latvia
Posts: 3 Kaklz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: Re: #30 How do i str_replace thats not case sensitive

#30 How do i str_replace thats not case sensitive

isn't it even easier to use eregi_replace() function?
PHP Manual reference

Reply With Quote
  #26  
Old February 15th, 2003, 03:40 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,360 Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)Sepodati User rank is General 9th Grade (Above 100000 Reputation Level)