|
http://php.net/manual/en/function.is-numeric.php Just an FYI. LifeSizePotato posted:Can I put in an .htaccess file "register globals on"? NO! Well you can, but don't write garbage ambiguous code! The PHP devs are trying to remove this sort of crap but of people are STILL writing code that relies on it then that is just a sad sad statement.
|
# ? Jan 8, 2010 14:20 |
|
|
# ? Jun 3, 2024 22:57 |
|
php:<? $clean = preg_replace('/[^\d]/', '', $_GET['id']); ?> e: oops, forgot that global isn't supported Munkeymon fucked around with this message at 21:24 on Jan 8, 2010 |
# ? Jan 8, 2010 16:15 |
|
Hammerite posted:... Did I miss something? Why wouldn't you use PHP's built-in (since 5.2) input filtering? php:<? $clean = filter_input(INPUT_GET, "id", FILTER_SANITIZE_NUMBER_INT); ?>
|
# ? Jan 8, 2010 19:46 |
|
Tivac posted:Did I miss something? Why wouldn't you use PHP's built-in (since 5.2) input filtering? Because id=2132+323213 would still get through. php Manual posted:FILTER_SANITIZE_NUMBER_INT : Remove all characters except digits, plus and minus sign. EDIT: To see, I whipped this up: code:
code:
Lumpy fucked around with this message at 20:26 on Jan 8, 2010 |
# ? Jan 8, 2010 20:16 |
|
What if you typecast it as an int like (int)$blah. I think PHP does this, I'm just hazarding a guess.
|
# ? Jan 9, 2010 14:08 |
|
haywire posted:What if you typecast it as an int like (int)$blah. I think PHP does this, I'm just hazarding a guess. That's what we suggested first of all, but it turned out that leading zeroes might need to be retained.
|
# ? Jan 9, 2010 17:28 |
|
Hammerite posted:That's what we suggested first of all, but it turned out that leading zeroes might need to be retained. That does make sense. I generally don't like the idea of this system in general, but hey.
|
# ? Jan 10, 2010 22:33 |
|
LifeSizePotato posted:This worked! I did discover that it's not registering an initial zero in the filenames, though. Since a lot of the document filenames are based on dates, I have some like 083008 (August 30, 2008) and it was trying to load 83008. That was causing some of the errors, so I guess I'll need to rename those files. php:<? $file = sprintf('%06d.html',$id); ?>
|
# ? Jan 11, 2010 22:08 |
|
I'm currently trying to get my webserver setup to handle php. I'm having a bit of trouble getting everything setup correctly though. It's a windows 2003 server. I installed php using the windows binary. I've added php to the web service extension and pointed it to php.exe I've also added .php to the websites application extensions list However when I run the page, I get the error: code:
I've searched php's site and did what they suggested and added the rights for IUSR_<computername> to the whole php directory. That gave me the same results. I was able to run phpinfo() from the command line and have it work. Anything?
|
# ? Jan 11, 2010 23:45 |
|
rotaryfun posted:I'm currently trying to get my webserver setup to handle php. I'm having a bit of trouble getting everything setup correctly though. Do you need to use IIS or have you considered installing XAMPP? If you're stuck with IIS, I'm pretty sure there is an installer for PHP that will integrate with IIS or at least give you detailed instructions if it can't/
|
# ? Jan 12, 2010 00:29 |
|
DarkLotus posted:Do you need to use IIS or have you considered installing XAMPP? I am unfortunately stuck with IIS. I downloaded the binary from http://windows.php.net/download/ is that what you were talking about? Also, I just realize, I didn't actually run phpinfo() from the command line, but rather php -i rotaryfun fucked around with this message at 00:41 on Jan 12, 2010 |
# ? Jan 12, 2010 00:38 |
|
rotaryfun posted:I am unfortunately stuck with IIS. Did you run the installer? PHP 5.2.12 installer Last time I tried on a windows box, it attempted to integrate with IIS. If it fails it will tell you what to do to make it work. http://www.php.net/manual/en/install.windows.iis6.php should help too
|
# ? Jan 12, 2010 00:46 |
|
From the link that I posted, I downloaded and installed the 5.3.1 VC9 non thread safe installer. I'll give previous version installers a try too. I did already see that page and followed it as well. I did have a question regarding the application extensions, should I have point to the php.exe or php-cgi.exe? Same question for the web extension services.
|
# ? Jan 12, 2010 01:21 |
|
rotaryfun posted:From the link that I posted, I downloaded and installed the 5.3.1 VC9 non thread safe installer. I'll give previous version installers a try too. With IIS you want the non thread safe installer. Try following these instructions: http://www.peterguy.com/php/install_IIS6.html Seem to have good information.
|
# ? Jan 12, 2010 01:32 |
|
DarkLotus posted:With IIS you want the non thread safe installer. Followed this and was able to get the server up and running with 5.2.5 There were only three differences between his guide and what I did initially. *He has you download the zip and not the windows installer. *He puts the php folders path into the registry as well as the Env Var Path *He points the application extension to the php5isapi.dll file rather than php.exe (which is what I thought had to happen but the windows installer doesn't even include the .dll) In the end it's up and that makes me pretty happy. Thanks for the link to the guide.
|
# ? Jan 12, 2010 18:51 |
|
I have a variable whose values can be anywhere from millions down to ten-thousandths stored in a MySQL database as type Decimal with a length of twelve and four decimal places. The problem is that when calling them though PHP I end up with results like: 0.3900 0.0001 4500000.0000 I would like the results to appear as: 0.39 0.0001 4,500,000 How can I truncate any zeros after the final digit to the right of the decimal point? Agrikk fucked around with this message at 19:41 on Jan 12, 2010 |
# ? Jan 12, 2010 19:19 |
|
Now that I've got my server setup to handle php, I'm trying to get the mail function to work. The server is a member of a domain and I did install smtp through IIS. It's set to anonymous. Here is the code that I'm trying to send, however it just goes to the next page and never actually sends the message. Nor does it give any error messages. php:<? $to = "<email>"; $subject = "<email>"; $message = "<email form data>"; $from = "<email>"; $headers = "From: $from"; mail($to,$subject,$message,$headers); header('Location:<thankyoupage>'); ?> rotaryfun fucked around with this message at 19:46 on Jan 12, 2010 |
# ? Jan 12, 2010 19:43 |
|
rotaryfun posted:Followed this and was able to get the server up and running with 5.2.5 You're welcome. Enjoy your IIS + PHP setup!
|
# ? Jan 12, 2010 21:32 |
|
Agrikk posted:I have a variable whose values can be anywhere from millions down to ten-thousandths stored in a MySQL database as type Decimal with a length of twelve and four decimal places. If round() doesn't help you out, try looking for a significant figures function you can use. Or write your own junk removal: Cast the number to a string, check for a decimal point, explode it at the decimal, check each number for avalue higher than 0, if the last number is true then keep it else ignore it.
|
# ? Jan 12, 2010 22:16 |
|
gwar3k1 posted:Cast the number to a string, check for a decimal point, explode it at the decimal, check each number for avalue higher than 0, if the last number is true then keep it else ignore it. That's a good one. Thank you. Edit: Here's what I did: php:<? function TruncateZeros($number) { list($front, $back) = explode(".", $number); if ($back <>0){ $array = array($front,$back); $dot_separated = implode(".", $array); echo "$dot_separated"; } else { echo "$front"; } } ?> Agrikk fucked around with this message at 02:07 on Jan 13, 2010 |
# ? Jan 12, 2010 22:58 |
|
Agrikk posted:That's a good one. Thank you. You're putting variables in quotes. I imagine it's printing either "$front" or "$dot_separated" instead of the values of those.
|
# ? Jan 13, 2010 18:27 |
|
gwar3k1 posted:You're putting variables in quotes. I imagine it's printing either "$front" or "$dot_separated" instead of the values of those. Nah, double quotes will use the value of variables you put into them. Single quotes won't, though.
|
# ? Jan 13, 2010 18:30 |
rt4 posted:Nah, double quotes will use the value of variables you put into them. Single quotes won't, though. "Either way, don't hide variables in there, just ".$use." concatenation";
|
|
# ? Jan 13, 2010 20:00 |
|
fletcher posted:"Either way, don't hide variables in there, just ".$use." concatenation"; It's not exactly hiding if your editor is smart enough to highlight the variable. It also makes it much easier to change a string that has variables in it.
|
# ? Jan 13, 2010 20:05 |
rt4 posted:It's not exactly hiding if your editor is smart enough to highlight the variable. It also makes it much easier to change a string that has variables in it. There are other reasons as well, namely localization.
|
|
# ? Jan 13, 2010 21:02 |
|
rotaryfun posted:Now that I've got my server setup to handle php, I'm trying to get the mail function to work. The server is a member of a domain and I did install smtp through IIS. It's set to anonymous. Try creating a php page with just php:<?php mail('me@mail.com', 'subject', 'Hello World', 'From: me@mail.com'); ?> Try a different smtp server. It could be the receiving email server is blocking the messages if your smtp server is not looking legit (spam protection). Maybe look into that or see if you are setup to receive bouncebacks. Turn on PHP error logging and look through the log. Look a the log on your smtp server if it has one. Maybe look at other php mail libraries, like swiftmail, to see if that might help.
|
# ? Jan 14, 2010 15:39 |
|
I just finished writing a WordPress theme from scratch with only knowing the HTML tags <b> and <i> prior to starting and I had to use PHP to do some of the things I wanted. This was basically accomplished by looking at other PHP code in the default templates, and coming from a programming background it wasn't too bad to figure out what tags did what. Anyway, I'm posting here because I want to learn some more PHP functionality because it seems interesting and it could never hurt to know. What are some easy/immediate level and interesting projects that I could take on to more or less learn by doing?
|
# ? Jan 15, 2010 06:36 |
|
Ziir posted:I just finished writing a WordPress theme from scratch with only knowing the HTML tags <b> and <i> prior to starting and I had to use PHP to do some of the things I wanted. This was basically accomplished by looking at other PHP code in the default templates, and coming from a programming background it wasn't too bad to figure out what tags did what. PHP+MySQL are practically synonymous when you first start writing more "complex" websites. Try learning how to use the two to provide a dynamic website (e.g. a blog). You can learn all kinds of poo poo depending on what kind of functionality you'd want from such a site. Obviously you've just setup a CMS but taking the above idea furthetr you can make a CMS for the blog. https://www.php.net is your friend. If you have firefox, there is a search engine extension too.
|
# ? Jan 15, 2010 09:20 |
|
Ziir posted:I just finished writing a WordPress theme from scratch with only knowing the HTML tags <b> and <i> prior to starting and I had to use PHP to do some of the things I wanted. This was basically accomplished by looking at other PHP code in the default templates, and coming from a programming background it wasn't too bad to figure out what tags did what. Build a single-user version of SimpleNote's web application. The core for supporting only one user is trivial, but you get to play with GET/POST parameters, and authentication / sessions, databases or flat-files as you choose etc. Oh: for extra credit build it twice: once 'raw' and once using a framework like CodeIgniter or Kohana - compare and contrast the experience! That's what I'm building to learn Google AppEngine and Python. Edit: you might like to expand on your programming experience; what kinds of other languages/environments and hobby or professional - that vastly changes whats a suitable / interesting project, and where are suitable resources for starting info. I mean my path is basically; BASIC -> C -> 6800 Assembler -> C++ -> Turbo Pascal + x86 Assembler -> Perl -> PHP + Javascript ... Python + Objective-C this year, hopefully. And from C onwards thats all been post-university professional, so the primer I needed on PHP was basically "uses $ in front of variables, very weak typing, <?php ... ?>, php.net exists ... go!" KuruMonkey fucked around with this message at 12:03 on Jan 15, 2010 |
# ? Jan 15, 2010 11:55 |
|
Ziir posted:Anyway, I'm posting here because I want to learn some more PHP functionality because it seems interesting and it could never hurt to know. What are some easy/immediate level and interesting projects that I could take on to more or less learn by doing? Other possible options, beyond what's already been suggested: Create a phone/address book. A todo list (with bonus 'email me when something is nearly due option). A simple Facebook Application. Any number of simple turn based games (tic tac toe, connect 4, etc). Lot of it does depend on what your interests are and how much programming knowledge you already have.
|
# ? Jan 15, 2010 16:43 |
|
PHPMyAdmin problem. I'm trying to restore my table of Users. There is a column called Name, which is VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL UNIQUE. I have three users with accented characters in their user names: 'Réglisse', 'rémi' and 'Pĺl'. When I use the "Import" feature in PHPMyAdmin, it truncates these users' user names at the accented character, so that they become 'R', 'r' and 'P' respectively. (I became aware of the problem initially when PHPMyAdmin complaimed of a MySQL unique key error message.) PHPMyAdmin exported these users' names correctly; I can see them in the .sql file it produced. Why won't it import them? I can disable the unique key, do the import, manually fix the names and then re-add the index, but that's not the point. There are other places in the database where accented characters appear (messages and the like) and I want to know what's going wrong. edit: A quick check shows it is doing this for every table. edit: In case anyone is wondering, I have dropped the tables and I am relying on the CREATE TABLE statements in the export to create the tables as well as populate them. Hammerite fucked around with this message at 20:49 on Jan 15, 2010 |
# ? Jan 15, 2010 20:37 |
|
It turns out that it imports successfully, and handles special characters correctly, if I just copy and paste the contents of the exported file into the SQL query window in PHPMyAdmin. God knows why that works and importing it the "proper" way doesn't.
|
# ? Jan 15, 2010 21:37 |
|
Hammerite posted:It turns out that it imports successfully, and handles special characters correctly, if I just copy and paste the contents of the exported file into the SQL query window in PHPMyAdmin. God knows why that works and importing it the "proper" way doesn't. I'm guessing the problem was that phpmyadmin wasn't opening the file in proper utf-8 format, or something.
|
# ? Jan 15, 2010 22:25 |
Hammerite posted:It turns out that it imports successfully, and handles special characters correctly, if I just copy and paste the contents of the exported file into the SQL query window in PHPMyAdmin. God knows why that works and importing it the "proper" way doesn't. There's always the mysqlimport command line utility.
|
|
# ? Jan 15, 2010 23:36 |
|
fletcher posted:There's always the mysqlimport command line utility. or mysql << datadump.sql
|
# ? Jan 15, 2010 23:37 |
|
I just started using CodeIgniter a couple days ago, but I see that the thread has gone to archives. In the CI "Create a Weblog in 20 Minutes" tutorial, the coder takes form data for submitting a comment and uses a single line of code to insert into the database. This happens at about 1:10 in the video. code:
Except I can't get it to work for me. The insert function is not stripping the form submit button from the $_POST data. I would prefer to not have to pick apart each element of the form data if possible. So what I'm asking is, what do regular users of CI do? Most of the tutorials I've found basically involve going through each form element and saving it separately from $_POST, then passing the whole thing to insert. This seems like wasted effort, but is there a good reason why I don't see people working that way? The CI docs even mention that the insert function automatically escapes the data, and I don't see any tutorial adding any extra security, so I'm wondering if there's a good reason. The video is two years old; maybe the functionality has changed?
|
# ? Jan 16, 2010 21:36 |
|
Firequirks posted:I just started using CodeIgniter a couple days ago, but I see that the thread has gone to archives. Seems like he's got the field names in the form lined up with the field names on the DB table, is yours set up the same way? And yes, using Active Record cleans data IIRC. Lumpy fucked around with this message at 22:31 on Jan 16, 2010 |
# ? Jan 16, 2010 22:26 |
|
Lumpy posted:Seems like he's got the field names in the form lined up with the field names on the DB table, is yours set up the same way? Yes, that's all correct. The only issue is that it's not stripping out the name and value for the Submit button from the $_POST array when inserting. The error specifically mentions that I'm trying to add a row to my ingredients table with a 'submit' column that doesn't exist: code:
|
# ? Jan 16, 2010 22:34 |
|
Firequirks posted:Yes, that's all correct. The only issue is that it's not stripping out the name and value for the Submit button from the $_POST array when inserting. The error specifically mentions that I'm trying to add a row to my ingredients table with a 'submit' column that doesn't exist: Don't give your SUBMIT button a name? EDIT: Yeah, I looked at his code in the video you posted, and there's no NAME attribute on the SUBMIT button. Lumpy fucked around with this message at 22:39 on Jan 16, 2010 |
# ? Jan 16, 2010 22:36 |
|
|
# ? Jun 3, 2024 22:57 |
|
Lumpy posted:Don't give your SUBMIT button a name? I had been using the Form Helper functions to make my form code:
code:
Edit: Perhaps I should do it entirely like the video, where he has written a no-view insert function? Firequirks fucked around with this message at 22:55 on Jan 16, 2010 |
# ? Jan 16, 2010 22:52 |