[PHP] strip ALL HTML tags in a page so only the text
I'm develloping a mail application, wich sends single part e-mail with PHP. for users who want the text version, I want to strip the HTML version and send what's left (plain text) to them. Can anybody tell me the best way to do this, I mean stripping all teh HTML tages with PHP. Thanx Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: strip ALL HTML tags in a page so only the text
thanx I look a little futher next time! erik "Ouster" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I think the best way is to use regular expressions. > > Erik <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED] > > I'm develloping a mail application, wich sends single part e-mail with > PHP. > > for users who want the text version, I want to strip the HTML version and > > send what's left (plain text) to them. > > > > Can anybody tell me the best way to do this, I mean stripping all teh HTML > > tages with PHP. > > > > > > Thanx > > Erik > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] What happened with zend engine version 2?
I believed that PHP V4.3 should include the Zend engine version 2 since there was two alpha releases for PHP-4.3.0 with Zend engine version 2 -PHP-4.3.0-dev-zend2-win32-alpha1 -PHP-4.3.0-dev-zend2-win32-alpha2 I'm waiting for Zend engine version 2. Where could I read information about future releases? I think the Zend engine version 2 provides much better coding facilities so I would preciate if anybody could answer my questions. Thanks /Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What happened with zend engine version 2?
After I posted the first message, I read something about PHP 5 at www.zend.com and suspected that is was about the new Zend Engine. I must have missed it totally! I was planning to code on a new website during my christmas holiday and now that chance is gone because the functionality in the new Zend Enginge is exactly what I miss. I also read on Zend.com that there are some decisions to make about some major changes i.e private members variables or not. I guess I have to switch to Linux and get a CVS-copy for PHP 5, if it exists? Maybe a Win32-binary? Does it exist and if it exists, what status does it have? Can you write code that will work when the final version is finished with minor changes, or are major changes on the agenda? And secondly, I have to face the fact that I cannot get the Zend Engine version 2 in a runtime environment for at least 6 month. You can be sure that I'm longing for it... :) "Rasmus Lerdorf" <[EMAIL PROTECTED]> skrev i meddelandet [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > That was never the plan. It is scheduled for PHP 5 sometime in the next > 6-12 months. > > -Rasmus > > On Tue, 24 Dec 2002, Erik Franzén wrote: > > > I believed that PHP V4.3 should include the Zend engine version 2 since > > there was two alpha releases for PHP-4.3.0 with Zend engine version 2 > > > > -PHP-4.3.0-dev-zend2-win32-alpha1 > > -PHP-4.3.0-dev-zend2-win32-alpha2 > > > > I'm waiting for Zend engine version 2. Where could I read information about > > future releases? > > > > I think the Zend engine version 2 provides much better coding facilities so > > I would preciate if anybody could answer my questions. > > > > Thanks > > > > /Erik > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What happened with zend engine version 2?
You don't need to answer my questions. Found almost all answers myself (Yes, I was "triggerhappy" to post my questions here before I looked for the answers...) I have one question though, in which status are Zend Engine 2 in? I mean, have you already taken the major decisions about (for an example) private members? "Erik FranzéN" <[EMAIL PROTECTED]> skrev i meddelandet [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > After I posted the first message, I read something about PHP 5 at > www.zend.com and suspected that is was about the new Zend Engine. > I must have missed it totally! I was planning to code on a new website > during my christmas holiday and now that chance is gone because the > functionality in the new Zend Enginge is exactly what I miss. > > I also read on Zend.com that there are some decisions to make about some > major changes i.e private members variables or not. > > I guess I have to switch to Linux and get a CVS-copy for PHP 5, if it > exists? Maybe a Win32-binary? Does it exist and if it exists, what status > does it have? Can you write code that will work when the final version is > finished with minor changes, or are major changes on the agenda? > > And secondly, I have to face the fact that I cannot get the Zend Engine > version 2 in a runtime environment for at least 6 month. > You can be sure that I'm longing for it... :) > > "Rasmus Lerdorf" <[EMAIL PROTECTED]> skrev i meddelandet > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > That was never the plan. It is scheduled for PHP 5 sometime in the next > > 6-12 months. > > > > -Rasmus > > > > On Tue, 24 Dec 2002, Erik Franzén wrote: > > > > > I believed that PHP V4.3 should include the Zend engine version 2 since > > > there was two alpha releases for PHP-4.3.0 with Zend engine version 2 > > > > > > -PHP-4.3.0-dev-zend2-win32-alpha1 > > > -PHP-4.3.0-dev-zend2-win32-alpha2 > > > > > > I'm waiting for Zend engine version 2. Where could I read information > about > > > future releases? > > > > > > I think the Zend engine version 2 provides much better coding facilities > so > > > I would preciate if anybody could answer my questions. > > > > > > Thanks > > > > > > /Erik > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OOP and object references, not copies - how to do?
Say the you are going to create a simple forum and you want to have a number of classes: Class Sql - handles the DB interface Class User - handles users Class Messages - handles messages When you are writing the code, you first creates a new sql object in order to read or write data from or to the database. Secondly you create a user object in order to handle users, for an example, to authenticate the user which is going to write a new message in your forum. The user object have a method which reads user information from the database. Since you alread have created a sql object, this method should use the sql object in order to fecth data from the database. I nice way to do this, would be to send the sql object as an reference to the user object constructor and store the object reference to the sql object in the user object. This is not working very well in PHP yet because PHP cannot treat objects as references. When you send the sql object to the user object constructor method, it will be a copy, not a reference! How do I get around this? There must be a way to handle this and create nice OOO PHP-code? I don't like using global variables as object handles. Best regards Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] function getting redeclared
Hi, I have a problem where I am getting the following error, and I was wondering if anyone has seen this one before and can help me out. "Fatal error: Cannot redeclare isvalidphonenumber() (previously declared in /home/bluekomo/public_html//classes/Registrant.class:360) in /home/bluekomo/public_html//classes/Registrant.class on line 360" I have a script, "registration.php", which calls require_once on the Registrant.class file mentioned in the above error message. The Registrant::setPhone() method is called more than once. Since it is called more than once, the function "isValidPhoneNumber()" defined within setPhone() is defined more than once, which I suspect is the source of the problem. Does PHP not allow you to define a function within a function and then call the enclosing function more than once? Here is the relevant section of code: 354 /** 355 * sets the phone property 356 */ 357 function setPhone($phone) { 358 // TODO: determine if these formats are acceptable 359 // TODO: account for extensions (separate form field?) 360 function isValidPhoneNumber($num) { 361 $valid = false; 362 if (preg_match('!\d{9,9}!', $num)) { 363 $valid = true; 364 } 365 if (preg_match('!\(?\d\d\d\)?-?\s*\d\d\d-?\s*\d\d\d\d!', 366 $num)) { 367 368 $valid = true; 369 } 370 371 return $valid; 372 } 373 374 if (isValidPhoneNumber($phone)) { 375 $this->phone = $phone; 376 } 377 } I am using PHP 4.3.0 on a RedHat machine with Apache 1.3.x. Thanks for your help, it's been a while since I've used PHP! Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function getting redeclared
On Tuesday, February 18, 2003, at 10:27 AM, Ford, Mike [LSS] wrote: I have a script, "registration.php", which calls require_once on the Registrant.class file mentioned in the above error message. The Registrant::setPhone() method is called more than once. Since it is called more than once, the function "isValidPhoneNumber()" defined within setPhone() is defined more than once, which I suspect is the source of the problem. Does PHP not allow you to define a function within a function and then call the enclosing function more than once? Well, it kinda does, but as it doesn't limit the scope in any way there's not really any point. Besides, it can lead to the kind of problems you're experiencing. Just declare the two functions sequentially in your include file. Okay, so PHP stores all functions that are not class methods in a global namespace? Or does it even do this with methods? Just curious so I don't depend on anything I'm used to from other languages thanks! Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: recursion?????
On Tuesday, February 18, 2003, at 10:58 AM, Johnson, Kirk wrote: The latest survey I've seen indicates that about 11% of browsers have JS disabled. About the same percent have cookies disabled. Too many for my tastes. Probably 8% of browsers have JS and cookies disabled for a reason (knowingly) and therefore can be considered the most dangerous segment of users. (Knowledge being power and all.) Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL DB Schema
On Tuesday, February 18, 2003, at 12:23 PM, Phillip S. Baker wrote: Is there an easy way to pull out the schema of a MySQL for viewing?? If you have access to the command line (either directly or via the system() function), try this: bash 2.05 $ mysqldump -t databasename --user=username --password Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL DB Schema
On Tuesday, February 18, 2003, at 12:39 PM, David Otton wrote: You want the tables and the relationships between them? Not easy to get the links because of the lack of foreign keys in MySQL. You can add a comment to your table with the COMMENT modifier, which gives you 60 characters to describe your table's relationship to other tables. (In a table named "registrants", you could have the comment registrants.user_id = users.user_id ) http://www.mysql.com/doc/en/CREATE_TABLE.html Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] escaping quotes for redisplay
Hi, I am running into a problem, that I'm certain I've had before but for some reason don't remember how to handle. If anyone can advise me on what to do here, that would be great. I have a PHP script that accepts some user input and validates it, and if the validation fails, it re-displays the form. In the form, the text fields' "value" attributes are set to the user's input so that the user doesn't have to fill everything out again. The whole system works great, and I'm sure you've all seen it a hundred times before. The problem happens when a user enters a single quote, such as in the string "O'Reilly". Re-displaying this value in the "value" attribute of the form, like this: is clearly invalid HTML, and it shows when the page is rendered in the user's browser (only the "O" gets through). If I turn on magic_quotes_gpc or use addslashes, the output is like so: And of course, when rendered, simply allows the "O\" to get through. I can solve this problem by using double-quotes instead of single-quotes for my attributes, and that is probably what I'm going to have to do. However, this means I can't let users enter double quotes, or the same thing will happen. In other fields, double-quotes might be necessary. Is there any other solution? Thanks, Erik PS: I am using htmlentities() on the output before displaying it in the browser, but it doesn't apply to singlequotes. I suppose I could str_replace it, but I'm wondering how other people handle this situation -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sorting results in PHP
bill wrote: Hi André, Sorting like that doesn't get it sorted by date. Each row has a lot of fields. It actually needs to be sorted three times by three fields, Year, Month, and Day. Because the query uses a GROUP BY statement, I can't sort it in the query. MySQL offers a DATE column type. You can extract a day, year, or month from this, without having to maintain three separate tables, using DATE_FORMAT. You can also sort by DATE in the query. Would this not be better for your situation? Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A faster way to Redirect pages
Poon, Kelvin (Infomart) wrote: I know this topic was discussed but I deleted my previous mail so I can't go back and review them. STFA: http://marc.theaimsgroup.com/?l=php-general My question is, is there a faster way to redirect html pages other than just using ? Is there any way we can do that in php so that it redirect "FASTER"? Right now I set the redirect time to be 1 sec, but for some reason it still takes kind of long until it actually redirects, I was wondering if there is any other way I can do this faster. Yes, check out the "header" function. You will pass it a string argument: $my_url = "http://php.net/header";; // your URL goeth here header("Location: $my_url"); Note that you have to call header /before/ you send output to the browser. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with dates
Brad Harriger wrote: I have two variables, $StartDate and &EndDate that contain values read from MySQL Date fields. How can I determine if a value entered by the user is between the two dates? I'm using PHP 4.0.6. if ($user_input > $StartDate && $user_input < $EndDate) { // do something } Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looking at individual chars of string
Bix wrote: Is it possible to look at individual chars of a string? eg: $str = "12345"; print $str_1 // Gives "1" print $str_2 // Gives "2" Try this: print $str{0}; // gives "1" print $str{1}; // gives "2" Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Fw: [PHP] Looking at individual chars of string
Kevin Stone wrote: Actually as far as the computer knows strings *are* arrays. Access any character within a string in the same mannor as you would access an element in an array. For example: $str = "hello world"; echo $str[4]; // prints o echo $str[6]; // prints w That works but is deprecated. Use curlies. http://www.php.net/manual/en/language.types.string.php#language.types.string.substr Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the difference: include()
Charles Kline wrote: What is the difference as in... why one or the other? include('somefile.php'); include("somefile.php"); Just wondering... If you had a constant named "somefile" or "php" and you use the second syntax, the constant would be interpolated/evaluated to the value of the constant. Generally I always use single quoted strings unless there's some need for double-quoted strings (like if I want to embed a variable) so something like this can't happen. Also good idea to only use capital letters for constants. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the difference: include()
Erik Price wrote: If you had a constant named "somefile" or "php" and you use the second syntax, the constant would be interpolated/evaluated to the value of the constant. Generally I always use single quoted strings unless there's some need for double-quoted strings (like if I want to embed a variable) so something like this can't happen. BTW, I'm talking out my butt here, but it might be true. The advice is still sound, regardless. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is the difference: include()
CPT John W. Holmes wrote: Well, the first part is out your butt... :) Yep. I tested it after making the assumption, sure enough I was WRONG. I've got to keep my butt under control, it's getting a little out of hand. To the OP, sorry 'bout that. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] copy ...
John Taylor-Johnston wrote: Captn John, What the difference? I recognise the code from my attempts at Perl. What's the diff between ^ and *? Is there a doc I can read up more on? ;) Swabbie John "Cpt John W. Holmes" wrote: What about eregi("TI(.*)¶",$line,$m) might want to use eregi("TI([^¶]*)¶",$line,$m) The first one says "eat TI then any number of characters until you get to the last ¶ in the target string, then eat that one too and stop there". The second one says "eat TI and then any number of characters that isn't a ¶, then when you finally get to one, eat it too but stop there". As for your doc, the definitive guide is <http://www.oreilly.com/catalog/regex2>. No, it's not a free web page somewhere, but it /will/ make you a master of regexes, something you can carry across all languages (except Perl6 :). I count it as possibly the most useful book I've ever read. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Loop Problem
[EMAIL PROTECTED] wrote: Ok, here's what I got. I'm trying to create an entire site that grabs all it's information (Page content, titles, link info, etc.) from a MySQL database. In this site I would like to have sub pages of master pages. For instance, Page 1 is a master page, Page 2 is a sub page of Page 1, and Page 3 is a sub page of Page 2 which is a sub page of page one. Now I would like to display this entire hierarchy if possible. Here's what I have but either I get an infinite loop or it doesn't work worth a damn mysql_connect("127.0.0.1","webuser",""); $query="SELECT * FROM PageInfo WHERE PageID>'0' and PageID=$MasterPage ORDER BY PageID"; I might be mistaken, but it looks like $MasterPage hasn't been defined at this point. This should be giving you an error. ($MasterPage gets defined later, but...) If you have your error-reporting turned off, it might not throw the error, so you are getting all the way to your DB. Try turning your error-reporting up and seeing if this causes you problems. The other thing is I don't understand your query -- why are you selecting where PageID is greater than something and at the same time where it is equal to something else? That is redundant. Finally, in your query, remove the single quotes around the 0. You don't need them, and it may be asking MySQL to treat the 0 as a character or string rather than an integer (and the column type is an integer). I'm not really definite on that last one though (more talking out the butt, I suppose). Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] complicated but fun, please help.
Daniel McCullough wrote: Where I am having problems at is when they need to update the poppasswd, which is a IMAP or QMAIL file. Plesk has files that will update the system, but it seems that I using the exec() and system() I can access those pl files. From the command prompt it works fine, html/php file doesnt work. Any thoughts? I would really appreciate the help, I'm doing this as a favor and would like to clear this off my plate. You probably are logged into the command prompt as a different user than what the PHP binary runs as. If the PHP binary runs as a user named "apache", and you log in as "dmcullough" or "root", and the commands you are trying to execute are restricted only to being run by "dmcullough" or a group that "dmcullough" is in but "apache" is not, then PHP won't run them. I'm assuming that you are using the system() or exec() commands, your email is a little difficult to understand in that respect... sorry. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to break out of nested loops
Bix wrote: I have a for loop within a for loop, and need to break out of both together... for ( blah ) { for ( blah ) { if ( true ) { break; } // only breaks out of this loop, how can I break it out of both loops. } } "break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of." from http://www.php.net/manual/en/control-structures.break.php Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] complicated but fun, please help.
Daniel McCullough wrote: Yes sorry for not being clear. I am trying to use exec() and system(). I guess I'm trying to see if there is another way to do it, like write to a file and have acron job run every minute or so, or if there is some way to make it seem like I am doing this with the right permissions. That sounds like a good plan. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about a text file and foreach
Jim Greene wrote: Hi All, I have a text file that has entries like the following: user1:mbox1: user1:mbox2: I basically do: $mboxs = `cat file | grep user1 | cut -d: -f2'; I then want to print out the data in the $mboxs variable (array) I am trying to use foreach but it does not work.. I am assuming the data is not considered an array? I might be mistaken, but wouldn't the value of $mboxs just be a string containing those characters? If you meant to use backticks to open up a shell pipe, I /think/ that's something you can do only in Perl. You can do it in PHP with the system() function, but it doesn't return an array but rather a string. You can parse the string into an array with string-processing functions. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Authentication
Beauford.2002 wrote: I am looking for a simple authentication script that uses MySQL. I have downloaded about 10 of them (most with no instructions on it's use), but even at that they are not what I need. The PEAR project has 7 different authentication packages, including Auth which I understand lets you design your own. PEAR code tends to be widely used and well-tested. Also there is a mailing list similar to this one dedicated to discussion of and support for PEAR projects. http://pear.php.net/packages.php?catpid=1&catname=Authentication When you go to the main page of my site it will ask you to login or signup. So I want to be able to authenticate the user if he logs in (not to much of a problem here, but I want to protect all pages (I don't want to use cookies as not everyone has these enabled). What other options do I have? If anyone knows a small script that can be modified, or point me in the right direction of how to do this, it would be appreciated. If you really want to reinvent the wheel, write an include file that is included onto every page of your site except your login page and the ones that you don't need to protect. This include file should check for a flag that indicates whether or not the user is logged in. If the user is not logged in, send a redirect header to the login page followed immediately by an exit() call. This way none of your scripts will be accessible without the user being logged in. To handle the login, the simple way to do it is to accept a username and password input from the user on the login screen and ship these to the database or wherever your user list is kept and test to see if they are valid. If they are valid, set the flag in the user's session indicating that they are logged in (which is checked by the include file). For maximum security, use SSL and beware the possibility of session hijacking. If you don't want to use cookies, you can either embed the SID in all hyperlinks of your site or just recompile PHP with the --enable-trans-sid flag (unless you're on PHP 4.2 or greater). Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sorting Recordset by a calculation between 2 Records
Vernon wrote: I am calculating distances between to record's zip codes using php and have a need to sort the recordset by that value. How do I do something like this? I mean it's not a value in the table that I can use the SQL ORDER BY statement. I want to be able to have the distances closest to the individual first. When you say "using php" I'm assuming that this means you are not doing the calculation at the database, but rather in your PHP code. Use the distance you've calculated as the numeric index of an array, pointing to the record that corresponds to that distance. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sorting Recordset by a calculation between 2 Records
Vernon wrote: Use the distance you've calculated as the numeric index of an array, pointing to the record that corresponds to that distance. Can you please expalin this statement? Perhaps a tutorial somewhere? I could explain it better if you could post the code that you have so far which extracts the records from the database. In other words, it's hard for me to explain it without seeing your records' structures. I don't know of a tutorial on this, when you see what I'm talking about you'll realize it's kind of basic. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php auth instead of .htaccess
Bryan Koschmann - GKT wrote: Hello, I have gotten used to using .htaccess to protect files/directories, but now I am looking at a need to authenticate against mysql. I have no problem actually getting it to authenticate, but I'm wondering what the simplest way to prevent someone from hitting anything other than the main page (and not needing authenticate) without having to login at every page. I'm assuming I would use something with sessions. Does anyone have a quick sample of how to do this? Yes, create a session variable using this syntax: $_SESSION['logged_in'] = false; Then authenticate the user. If the authentication succeeds, then change the variable's value to true. $_SESSION['logged_in'] = true; Now on every page except your login page, test for the session variable before displaying the page. If it's present and valid, display the page as usual, if not, redirect to the login page. if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) { // display page } else { header("Location: http://domain.com/login";); exit("Sorry, you are not logged in."); } The details are all in the manual under "Sessions" and Session-related functions. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Processing Order || Function Calls
CF High wrote: Hey all. I was under the impression that PHP processes all php code first before handing HTML processing over to the browser. http://www.php.net/manual/en/ref.outcontrol.php Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sorting Recordset by a calculation between 2 Records
vernon wrote: I think that maybe I should explain the fist Zip comes from a session, here I've defined the variable. I use the caluation in the code to get the distance and then loop the recordset so that the distance is created each time the record loops through. I have taken many things from the file and am only looking for what we discussed, to sort the records by distance. I see. When you have a collection of items, the best place to put them is in an array. I assumed that you were going to be putting them into an array anyway, so my solution simply explained a different way of putting them into an array so that you would easily be able to determine the distance if given any element in the array. There might be ways to solve your problem without using arrays, but I wouldn't waste any time investigating them. Use arrays for this, that's why they exist. I've CC'd this back onto the list since this kind of discussion can be helpful for others who are learning too. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] nstalling PHP
Marc Bakker wrote: Hello all, I installed PHP, Apache and MySQL. I read the install.txt file that came with php and changed the default values in php.ini and httpd.conf. When I restart Apache and type my local website (127.0.0.1/index.php) IE comes with a 'Save file As' dialog box. Instead of parsing the php code and returning html code, Apache returns the index.php file! Does the AddType line in httpd.conf so that files ending with the extension ".php" are processed by the PHP binary? You should have a section in your httpd.conf that looks something like this: # a bunch of lines go here # a bunch of lines go here # a bunch of lines go here # a bunch of lines go here # a bunch of lines go here AddType application/x-httpd-php .php .php3 #<--- you need this line Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP to get a word count of a MSword doc
Brad Wright wrote: Thanks for the reply Rene, Any change of a code sample of how u did this?? Im not at all experienced in Java. According to the manual, PHP does have some tokenizer functions: http://www.php.net/manual/en/ref.tokenizer.php However, the documentation appears to be lacking as they are still under development. Using it might be somewhat straightforward if you are accustomed to using a tokenizer in another language (like Java) but if not, it's really a little too difficult to explain in an email. A less elegant but ultimately quicker and probably more reliable solution might be to investigate some kind of external word-counting program that knows how to parse .DOC files (good luck on that part), and call this from your PHP script using system(). Catch-22: the only libraries I am familiar with that can parse .DOC files are the Jakarta POI libraries, which are written in Java. But I am sure that if you scour the web you can find some Perl, Python, or maybe even PHP-based solution. Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using PHP to get a word count of a MSword doc
Brad Wright wrote: Erik, thanks, are you able to pint me to some good reference sources on tokenizer's... i have never come across them before I have been scouring the web, and am coming up a decided blank. :) The only tokenizers I have used are the StringTokenizer and StreamTokenizer classes in Java. If you want to learn about these, go to this web page: http://www.mindview.net/Books/TIJ/ and download the book "Thinking in Java". Chapter 9 is the chapter that covers File I/O and discusses how to use them. I have a feeling that the PHP tokenizers work very similarly to the Java one (just judging from the docs on the PHP site). Good luck, Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Remote file information (PHP 4.0)
Is there a way, when requesting remote files (using fopen() or file()) to determine the base directory of the file retrieved? For instance, if I did: $file = file("http://www.host.com/directory/php";); Several things can happen. One is that theres an actual file named php that is retrieved. Secondly, php could be a directory and the file index.html is retrieved from that directory. Or php could be a directory without an index, in which case a directory listing is generated or something to that effect. But what I want to be able to do is to determine what the base directory is in any case. For instance if php was a file, the base would be http://www.host.com/directory/, if it was a directory with an index the base would be http://www.host.com/directory/php. Anyone know if this information is available? Thanks, Erik Fears. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] scope of class atts in methods
Hi all, a quick question about using PHP's objects, specifically in terms of the scope of class attributes: Normally, in PHP, a variable in a function is local to that function and is NOT a reference to a similarly-named variable outside the function, right? To the best of my knowledge, there are several ways to allow access to an outside variable from within a function: 1) Declare the variable as global with the "global" keyword 2) Access it from the $GLOBALS array 3) Pass the variable to the function as a parameter and probably others, but it's really beside the point because I don't have a question about normal functions. What I am really wondering is if there is any formal "rules" about the scope of Class Attributes in Class definitions and in methods -- they do not behave identical to PHP's functions. For instance, I can access a class attribute from within a method of that class without explicitly declaring that attribute global inside the method, or without explicitly passing that attribute as a parameter to the method. So they seem to behave as if they are always global. But if I want to make a change to that class attribute from within a method, am I affecting a copy of the class attribute, or the class attribute itself? The reason I ask is because I have a Class that is behaving oddly. Here is the relevant part of the code: Class Folder { // declare class attributes var $contents = array(); // a method to add to $contents function add_to_contents($item) { $this->contents[] = $item; } // a method to remove from $contents function rm_item($index) { unset($this->contents[$index]); } } The crux of my question is, does this have the effect that it appears to have? I am hoping someone with thorough understanding of the internals of PHP can give me a definitive answer. My tests are coming up with strange results, so I haven't figured it out on my own yet. Thanks in advance, Erik PS: FYI, if you unset an array element, there is still an index for that element -- the array does not reindex itself. A good solution to this, that a fellow lister named Nathan gave me, is to array_push() a dummy var onto the end of the array and then array_pop() it back off -- this reindexes the array. But I am finding that somehow my arrays are "remembering" old elements that I could have sworn I unset, so I am asking the above question about the scope of class attributes in methods. Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OOP style question
I'm trying to solve my earlier-posted dilemma of a class attribute (array) that is "remembering" elements that should have been unset(). The good news is that, according to some testing I've been doing (I have separated the relevant code and am directly testing it), it looks like PHP is behaving as expected -- I really hope that it's just an error on my part, so that I can fix it. But out of this exercise I have begun to wonder something. If someone who is better-schooled than I in object oriented programming style could respond I would be very grateful. I have a method in my class that essentially unsets an array element. The frequency with which this method is called varies depending on the circumstances, so i can't "hard-code" the solution to this problem. But after the method is done being called (however many times it need be called), a second method needs to be called. Think of this second one as a "clean up" method, that needs to be called anytime the first method is called, but ONLY ONCE per script instance, no matter how many times the first method was called. This means that I can't just call method #2 every time I call method #1. Now, originally I was doing all of this method calling from the script itself. For each variable POSTed by the user, I call the first method. But now that I have a second "clean-up" method that needs to be called, how should I go about it? Should I have one "master" method in the class that is called from the script, and itself does all the work? This keeps all of the work in the class, and out of the calling script. OR... Should I keep the class free of code that only executes according to POST variables from the user, and keep this kind of thing in the calling script. That way, the object's class is more flexible, and can be used in more contexts. Again, this is really a question of style -- I can get it to work either way. I'm just wondering if a class should be written to handle ALL CODE related to its class, and keep most of the work in "private" methods (not really enforced in PHP but whatever), or whether the class should be written so that it has a lot of public methods that can be called from the script, which means that the class is more flexible in the long run? A question of encapsulation vs modularity, it would seem. Your thoughts are gratefully accepted. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP style question
Thanks Scott, That's kind of what I thought -- that there's no cut-and-dried answer to the question I asked. I'm actually amazed that it came out coherently enough for someone to understand it and answer! Your solution is a good one. On the one hand this is less modular, since it tests for certain conditions that have to exist (i.e., the POSTed variables) and thus requires a completely different method for completely different conditions, but on the other hand, it does nicely keep all of the code in the class so that the script doesn't get bogged down with many method calls. I do one call to dothis(), which does all my work, and then I'm done. That's what I'll go with, thank you. Erik On Thursday, June 6, 2002, at 05:09 PM, Scott Hurring wrote: > It depends highly on what you're doing and how you're doing it :) > > If somethign needs to be done *always*, just throw it into the > Object so that the user won't have to call it explicitly, > however if you want to provide fine-grained control over > how/when/why things are cleaned-up, you might want to > keep it "public" and let the user call it explicitly. > > > For example, if clean-up is automatic, and only once-per-session, > this might be somewhat along the lines of what i think you're > asking for::: > > function dothis($form) > { > // . do whatever to POSTED variables > > $this->cleanup($form); > } > > function cleanup($form) > { > // Only run once per instance > if ($this->cleanup_called) > return 1; > $this->cleanup_called = 1; > > // ... do cleanup > } > > --- > Scott Hurring > Systems Programmer > EAC Corporation > [EMAIL PROTECTED] > Voice: 201-462-2149 > Fax: 201-288-1515 > >> -Original Message- >> From: Erik Price [mailto:[EMAIL PROTECTED]] >> Sent: Thursday, June 06, 2002 4:58 PM >> To: [EMAIL PROTECTED] >> Subject: [PHP] OOP style question >> >> >> I'm trying to solve my earlier-posted dilemma of a class attribute >> (array) that is "remembering" elements that should have been >> unset(). >> The good news is that, according to some testing I've been >> doing (I have >> separated the relevant code and am directly testing it), it >> looks like >> PHP is behaving as expected -- I really hope that it's just >> an error on >> my part, so that I can fix it. >> >> But out of this exercise I have begun to wonder something. >> If someone >> who is better-schooled than I in object oriented programming >> style could >> respond I would be very grateful. >> >> I have a method in my class that essentially unsets an array >> element. >> The frequency with which this method is called varies >> depending on the >> circumstances, so i can't "hard-code" the solution to this >> problem. But >> after the method is done being called (however many times it need be >> called), a second method needs to be called. Think of this >> second one >> as a "clean up" method, that needs to be called anytime the >> first method >> is called, but ONLY ONCE per script instance, no matter how >> many times >> the first method was called. This means that I can't just >> call method >> #2 every time I call method #1. >> >> Now, originally I was doing all of this method calling from >> the script >> itself. For each variable POSTed by the user, I call the >> first method. >> But now that I have a second "clean-up" method that needs to >> be called, >> how should I go about it? Should I have one "master" method in the >> class that is called from the script, and itself does all the work? >> This keeps all of the work in the class, and out of the >> calling script. >> >> OR... >> >> Should I keep the class free of code that only executes according to >> POST variables from the user, and keep this kind of thing in >> the calling >> script. That way, the object's class is more flexible, and >> can be used >> in more contexts. >> >> Again, this is really a question of style -- I can get it to >> work either >> way. I'm just wondering if a class should be written to >> handle ALL CODE >> related to its class, and keep most of the work in "private" methods >> (not really enforced in PHP but whatever), or whether the >> class should >> be written so that it has a lot of public methods that can be called >> from the script, which means that the class is more flexible >> in the long >> run? >> >> A question of encapsulation vs modularity, it would seem. >> >> Your thoughts are gratefully accepted. >> >> >> >> Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] scope of class atts in methods
If anyone read this post, you probably already forgot about it, but I just wanted to clarify that I found the source of the problem and it was a coding mistake on my part, not a problem with PHP's array implementation. Erik On Thursday, June 6, 2002, at 03:11 PM, Erik Price wrote: > Hi all, > > a quick question about using PHP's objects, specifically in terms of > the scope of class attributes: > > Normally, in PHP, a variable in a function is local to that function > and is NOT a reference to a similarly-named variable outside the > function, right? To the best of my knowledge, there are several ways > to allow access to an outside variable from within a function: > > 1) Declare the variable as global with the "global" keyword > 2) Access it from the $GLOBALS array > 3) Pass the variable to the function as a parameter > > and probably others, but it's really beside the point because I don't > have a question about normal functions. What I am really wondering is > if there is any formal "rules" about the scope of Class Attributes in > Class definitions and in methods -- they do not behave identical to > PHP's functions. For instance, I can access a class attribute from > within a method of that class without explicitly declaring that > attribute global inside the method, or without explicitly passing that > attribute as a parameter to the method. So they seem to behave as if > they are always global. > > But if I want to make a change to that class attribute from within a > method, am I affecting a copy of the class attribute, or the class > attribute itself? The reason I ask is because I have a Class that is > behaving oddly. Here is the relevant part of the code: > > Class Folder > { > // declare class attributes > var $contents = array(); > > // a method to add to $contents > function add_to_contents($item) > { > $this->contents[] = $item; > } > > // a method to remove from $contents > function rm_item($index) > { > unset($this->contents[$index]); > } > } > > > The crux of my question is, does this have the effect that it appears > to have? I am hoping someone with thorough understanding of the > internals of PHP can give me a definitive answer. My tests are coming > up with strange results, so I haven't figured it out on my own yet. > > Thanks in advance, > > > Erik > > PS: FYI, if you unset an array element, there is still an index for > that element -- the array does not reindex itself. A good solution to > this, that a fellow lister named Nathan gave me, is to array_push() a > dummy var onto the end of the array and then array_pop() it back off -- > this reindexes the array. But I am finding that somehow my arrays are > "remembering" old elements that I could have sworn I unset, so I am > asking the above question about the scope of class attributes in > methods. > > > Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] > > > -- PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Thumbnail pages - alot of them
On Friday, June 7, 2002, at 03:06 AM, rory oconnor wrote: > I have a mysql database table of about 7000 images (they are not > actually in the db, just references), as yet uncategorized. I need to > put them online and allow my client to browse 12-18 thumbnails per page. > > what would be the most efficient method to code that with PHP? any help > is appreciated! First a disclaimer -- what I am about to tell you may sound very complicated, but only because it's hard to explain. Really, the concept is simple once you "get" it. Some people have said look into the LIMIT clause in a MySQL SELECT query. This is the right direction, but specifically you need to use the (implicit) OFFSET argument to LIMIT. Fundamentally, what you do is this: You perform a SELECT as normal, which would return all results from your database, but you use LIMIT 0, 10 which means "Limit it to 10 records starting at the first one". [Yes, it's weird since your row's primary key column probably starts with 1, but if you think about it it's not really weird, MySQL doesn't care what value is in your row's primary key column. The first record/row is 0.] The offset is going to be passed via a GET variable, so your query will look something like: SELECT row_id, row_content FROMtable WHERE where conditions here LIMIT $offset, 10; This is because if the person clicks the "next 10 rows" link, which you will provide, this link will have a querystring attached that looks something like "?offset=10" or whatever offset it is. So how do you implement this into a PHP script? Well, sure there's a lot of ways to do it but essentially, you do this: On the first page, you have two queries -- first a COUNT to see how many records are in the table, and second the above SELECT query that does the work you want done (getting the information). Now, using the first query's results (which are nothing more than the number of records in the table), you figure out how many more rows are left AFTER the offset that you are at. If this is the first page, and you are displaying ten results on the first page, then simply subtract ten from the total. If this is the second page, you have now displayed twenty records, so subtract twenty. Save this value as a variable like $rowsLeft or something. Also, you want to save the number of rows PREVIOUS to your current offset, which for the first page would be 0 but for the second page would be 10, and for the third page would be 20. Get it? This is how you will make a link that says "next 10 thumbnails" or "previous 10 thumbnails" or whatever. Next step is easy: you simply display the data however you wish to do it. I'm not going to tell you how to do this because it's the same way you'd display the data normally. Finally, you need to make the links to go backward or forward. This is the whole trick of the operation. You make a link to the page's self, but you pass along the offset so that the next query knows how to build the proper SELECT statement to return the -next- ten rows, etc. Like this: print("Next 10 Thumbnails"); Of course, the above link is really too simple. You would want to determine the number of rows that will be returned, which will usually be 10 but not always -- on the second to last page, if there are only 4 rows left to display, you don't want to say "Next 10 thumbnails" if there are only 4 left. So you need to do a simple bit of processing to get the number of rows left and print that value. Do the same for the "previous 10 thumbnails", although if you do this right you will always have a value of 10 in this section. (When would you ever end up at an offset that is not a multiple of 10?) That's all there is to it. It's complicated at first, but once you get it, you'll always be able to do it. I strongly recommend that you create a class called "ThumbnailResults" and store all of this logic in the class, since it'll keep your script cleaner. Good luck, Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] NEWBIE- Is this possible? How?!
On Thursday, June 6, 2002, at 11:07 PM, Kevin J wrote: > I am sure this isn't the best way to learn PhP, but I am running out of > ideas for making this website work. Static content just seems boring > these > days, so I would liek to "spice" up the site by having the band members > themselves contribute to the site, instead of me always doing it. > > It might bring people to the site more often, and make it more > interesting > for the band members. > > I just have to figure out whwre to start, thats all. Everything you want to do is covered in "Beginning PHP" (Wrox), which is tutorial in nature. This is for someone who is new to PHP, and new to coding in general. PHP is an excellent first language because it is easy to learn, and you can see immediate results in your new dynamic web pages. On the other hand if you already know how to program, you would probably be better served by an introduction to the language that is aimed at programmers, such as O'Reilly's new offering "Programming PHP" by Keven Tatroe and Rasmus Lerdorf (who started the PHP project). Managing the database will take another level of skill, so pick up Paul DuBois' "MySQL" (New Riders) which IMO is unmatched by any other reference on the topic. But don't expect to become an overnight wizard. There are a lot of security issues with which you will have to familiarize yourself, ranging from system/server security to the security of your code itself. If your site will be low-traffic, then I wouldn't worry too much, but if it is like N-Sync or something like that then I imagine there are tons of annoyed crackers out there who would happily try to break into the site to wreak damage. The one great thing about a totally static web site is that (at the coding level), there is no fear of security issues -- its simply a glorified text file. (The reason I say "at the coding level" is because server security is still an issue.) But don't get scared off with this warning... just go get started with programming in PHP, and you will eventually learn what you need to as you go. Just don't put it on the real site until you're sure it's done, so all your development locally or something. Erik PS: don't overwrite old stuff, you might want that someday. If a band member wants to post a commment, just let them insert a new record into the database and only return the most recent record for each band member. Archive the old data, perhaps when you are feeling adventurous you can offer a "read the archives" section of the site. Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP style question
On Friday, June 7, 2002, at 12:50 AM, Analysis & Solutions wrote: > On Thu, Jun 06, 2002 at 04:57:42PM -0400, Erik Price wrote: > >> I have a method in my class that essentially unsets an array element. > > Uh, I know you're a sharp guy, but I've got to ask anyway. If it's > doing such a simple thing, why do you need a method to do it? Why not > go ahead and unset the array directly? Well, for two reasons -- one, it does a few more things than just unsets the element (such as checks for certain condition). The main reason, however, is that I'm trying to get into the habit of using accessor/mutator methods in my classes. PHP lets me directly manipulate attributes from the class, but Java doesn't, and I'm learning Java in my spare time, so... I'm basically foregoing some of the luxuries of PHP in order to be more strict in my coding. >> Now, originally I was doing all of this method calling from the script >> itself. For each variable POSTed by the user, I call the first method. > > Why not have the function automatically check each variable in POST (you > know, do a while loop for each $_POST) rather than have to call the > function over and over? That way you can call the thing once and you're > done. Plus, you can then either put that second, clean up, step in here > or have it a separate function called at the end of this POST check > stuff. Yes, that's an excellent idea. It's pretty much what I ended up doing in my class, though I didn't loop through the POST data (rather, I wrote my code to anticipate certain POST data and it acts upon that). IOW I went with the "encapsulation" over the "modularity" for my class. I can always add another method for another situation where the conditions are different if need be. >> But now that I have a second "clean-up" method that needs to be called, >> how should I go about it? Should I have one "master" method in the >> class that is called from the script, and itself does all the work? >> This keeps all of the work in the class, and out of the calling script. >> >> OR... >> >> Should I keep the class free of code that only executes according to >> POST variables from the user, and keep this kind of thing in the >> calling >> script. That way, the object's class is more flexible, and can be used >> in more contexts. > > I tend to use classes for reusable purposes throughout my projects. > So, I wouldn't bog it down with things you're only going to use in one > place. Perhaps put this second, clean-up, process in an extension of > the primary class? Well, the way I end up doing it, there are a few methods that do actual work and then there are... how should I put it... "master methods" that are invoked from the script and call these "worker methods" depending on the situation. True, I will have to create a new "master method" later if I need to use this class again in a different context with different POST data, but all the work is really done, the "master method" simply calls the appropriate "worker methods" and can be whipped up in no time. Thanks Dan, Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Extracting specific data from a URL using PHP...
On Thursday, June 6, 2002, at 06:57 PM, Anthony Ritter wrote: > I understand that one can open a page off an existing website to extract > text data using a PHP script by using the fopen and fread functions. > > And by using the strip_tags() function, one can extract data without the > html markup as a literal string. > > Here's my question... > > Let's say that a html page from a website out on the 'net consists of > three > paragraphs of text and four html tables. > > Within each of those tables is text. > > And let's say that the second table down has three columns - water > temperature, water level and cfs flow along with numerous records. > > Is there any way to extract *specific* data off a page - in this case - > the > second table - while leaving the balance of the text and the other > tables > 1, 3 and 4) alone? Yeah, you'll have to parse the page. Use regexes. Unlike a lot of functionality in PHP, there's no simple way to do it, you'll have to roll up your sleeves and bust out some parsing routines. Just remember that an HTTP resource (such as an HTML document or whatever data is sent by a web server) is a stream of bytes, or characters, and you can use regexes to search for certain patterns in those characters and perform certain operations if certain patterns are "matched" in the bytestream. Fundamentally, this is why there is a movement toward XML -- it is a way of identifying certain chunks of data in a standards-based fashion so that it can be parsed more easily. There are tons of libraries for doing this*, so you may want to look into it. If your target data is in XML format you will have a much easier time of it than if it is an HTML-based web page. That's why some sites are providing the option of an XML page or an HTML page, because they recognize that sometimes the agent requesting the page is not a human but rather a program. You may be interested in something called RDF (I think) for which PHP libraries have already been written (I think) and will do most of the work for you. Erik * two popular ways of handling XML are: - the SAX methodology: you set event handlers which activate and perform specified actions when a certain tag is encountered in the course of reading the bytestream - the DOM methodology: the entire bytestream is read into memory and then can be treated as a tree with nodes, and you can access these nodes directly Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Access control question
You are also assuming that the session hasn't been hijacked. Other things you can do are store the user's UserAgent in a session var and check it on every page (session spoofer MIGHT be using a different browser), and do likewise for IP address. Although remember that AOL users will have problems with this, since their requests do not always originate from the same IP address. There is a class on the zend website, called "Introduction to Classes" or something, that has a nice security class you can use. But to answer your question, I don't think you need to check another session variable to see if they're logged in. If they have user_id session variable, then they have a session, and are logged in, afaict. You're really testing different elements of the same $_SESSION array, so the presence of any session var means that a session is established. Erik On Friday, June 7, 2002, at 11:25 AM, Jeff Field wrote: > Quick question... > > I have a site where user's log in, they put their user name and > password in > a form and if they are verified against the database, session variables > are > created, > > $_SESSION['user']; > $_SESSION['pass']; > > and they get sent to the next page by way of, > > header("Location: https://www.mysite.com/login/";); // not a real site > > On that page, and all other pages for which I want to control access, I > then > put a little access control script (actually, an include file) at the > top of > each page that checks to see that $_SESSION['user'] is present. If > $_SESSION['user'] is *not* present, I send them back to the login > page. If > $_SESSION['user'] *is* present, they're granted access to the page. > > Here's the question: > > Is it simply enough to just check that $_SESSION['user'] is present, and > therefore, by that alone assume the user has logged in and should be > granted > access? Or, should I be verifying the $_SESSION['user'] and > $_SESSION['pass'] against the database on every page? > > The reason I ask is that an article (tutorial) on access control runs a > script that hits the database every page. But, to me, that seems like a > waste because simply having the $_SESSION['user'] present means they've > already logged in. Am I missing something here? > > Thanks, as always! > > Jeff > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Access control question - follow-up question
On Friday, June 7, 2002, at 12:32 PM, Jeff Field wrote: > I'm under the impression that when I create the user > and password variables, the variables are only available in the session > cookie on my own server, not in the cookie that is sent to the user to > maintain sessions. The cookie sent to the user merely contains the > session > ID. Therefore, other than someone hijacking the session, I'm a little > unclear as to the security risk. Have I got this right? Exactly. Unless they had access to the server itself, where the session data is stored in a temporary file. So there are two vulnerabilities -- server compromise and cookie spoofing. But don't forget that without SSL, someone watching your client's port (or your server's port) will see the password in plaintext and get through that way. Watching a port is about as easy as anything I can think of. So for true security you'll need SSL. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convertion from string to time & substracting
On Friday, June 7, 2002, at 02:01 PM, juaid wrote: > sorry if maybe this is a bit dumb question, but I'm a begginer with > php... > > I got a mysql database, where two of the fields of a table record times > as > CHAR(8) in the format hh:mm:ss > > I want to take this two times and get the difference between them in > seconds, for example 12:01:30 - 12:00:00 = 90 > I looked up at the doc in the php.net website and couldn't get on how > to do > this... should I use the strtotime function? > > anyone has donde something like this, or knows what functions could > help me > to do this? First of all, if you're storing time then you're better off using the DATETIME column type. Even though it may take a bit more space than CHAR(8), unless you absolutely need the ultimate in table optimization, use DATETIME. It makes comparisons and manipulations like the one you are trying to do much easier. (Because you can convert them to UNIX_TIMESTAMP and then do your math on that, which is a piece of cake.) But to answer your question, here's what I would do: // $db contains database connection handle $sql = "SELECT row FROM table WHERE where_clause"; // attempt to pull data from DB if (!$result = mysql_query($sql, $db)) { die('Query failed.'); } // assuming only one row is returned $row = mysql_result($result, 0); $time_array = explode(':', $row); $hours = $time_array[0]; $minutes = $time_array[1]; $seconds = $time_array[2]; // convert to timestamp so we can easily do math $timestamp = mktime($hours, $minutes, $seconds, 0, 0, 0); Now all of your times are in timestamp form, and you can do what you need to do. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convertion from string to time & substracting
On Friday, June 7, 2002, at 02:22 PM, Erik Price wrote: > First of all, if you're storing time then you're better off using the > DATETIME column type. Even though it may take a bit more space than > CHAR(8), unless you absolutely need the ultimate in table optimization, > use DATETIME. I meant TIME. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convertion from string to time & substracting
I thought that it was a CHAR column. I didn't know you could use UNIX_TIMESTAMP() on CHAR columns, so I was showing him how to turn his colon delimited strings into timestamps with mktime(). Erik On Friday, June 7, 2002, at 02:27 PM, John Holmes wrote: > Umm...How about using UNIX_TIMESTAMP() in your query, then you won't > need any of that PHP code you just wrote... > > ---John Holmes... > >> -Original Message- >> From: Erik Price [mailto:[EMAIL PROTECTED]] >> Sent: Friday, June 07, 2002 2:22 PM >> To: juaid >> Cc: [EMAIL PROTECTED] >> Subject: Re: [PHP] convertion from string to time & substracting >> >> >> On Friday, June 7, 2002, at 02:01 PM, juaid wrote: >> >>> sorry if maybe this is a bit dumb question, but I'm a begginer with >>> php... >>> >>> I got a mysql database, where two of the fields of a table record > times >>> as >>> CHAR(8) in the format hh:mm:ss >>> >>> I want to take this two times and get the difference between them in >>> seconds, for example 12:01:30 - 12:00:00 = 90 >>> I looked up at the doc in the php.net website and couldn't get on > how >>> to do >>> this... should I use the strtotime function? >>> >>> anyone has donde something like this, or knows what functions could >>> help me >>> to do this? >> >> First of all, if you're storing time then you're better off using the >> DATETIME column type. Even though it may take a bit more space than >> CHAR(8), unless you absolutely need the ultimate in table > optimization, >> use DATETIME. It makes comparisons and manipulations like the one you >> are trying to do much easier. (Because you can convert them to >> UNIX_TIMESTAMP and then do your math on that, which is a piece of > cake.) >> >> But to answer your question, here's what I would do: >> >> // $db contains database connection handle >> $sql = "SELECT row FROM table WHERE where_clause"; >> // attempt to pull data from DB >> if (!$result = mysql_query($sql, $db)) { >> die('Query failed.'); >> } >> >> // assuming only one row is returned >> $row = mysql_result($result, 0); >> >> $time_array = explode(':', $row); >> $hours = $time_array[0]; >> $minutes = $time_array[1]; >> $seconds = $time_array[2]; >> >> // convert to timestamp so we can easily do math >> $timestamp = mktime($hours, $minutes, $seconds, 0, 0, 0); >> >> Now all of your times are in timestamp form, and you can do what you >> need to do. >> >> >> >> Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Javascript & PHP cookies
On Sunday, June 9, 2002, at 12:56 AM, John Taylor-Johnston wrote: > Absolutely. I've done it. Cookies are cookies. > > What I don't like is that the cookie is not saved unitl after a submit. > > In Javascript, I have JS code that will assign a value and save it to a > cookie and then recall the cookie value and document.write(myvalue), > over and > over if I want, without EVER submitting. It works as the page loads. > > Need JS code? Yes, because it's a client side operation. Remember, it's the submit that is telling the web server to send a cookie. JavaScript code, being client side, can set the cookie without a page submit, just like a mathematical calculation can be done without a page submit in JavaScript but not with PHP. To further this clarification, the reason why you can't read the cookie that you're setting in the same page is because that cookie was never sent to the web server for PHP to recognize. In other words, you may think that because you set a cookie at some point during a given script (that is sent to the user agent), that cookie is now available later in the same script. It's not. The cookie needs to be sent to the web server with a page request in order for the web server/PHP to know it's there. This hasn't happened yet. To beat a dead horse, this is exactly what happens in this order, and the steps are separate: 1. User makes a GET/page request of the web server 2. The resource requested on the web server is a PHP script, and one of its effects is to say "when this resource is sent to the browser, give this cookie along with it" 3. Only AFTER the script executes and is transmitted (thus only AFTER the script is actually done doing its work) does the cookie appear on the client side. So the script is unable to "read" the cookie it is setting. 4. If the user makes another request to that domain, THEN the cookie is available, because the cookie is sent along with that request. In JavaScript, all of this is done on the client side, so the cookie can be read immediately once it is set without the need for requests and page submits or what have you. If you think in terms of HTTP it all makes total sense. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question
On Monday, June 10, 2002, at 12:17 PM, Jay wrote: > I was wondering can I create a new Object inside of a different class? > > class One > { > //constructor > function One > { > $this->two = new Two; > $this->test = $this->two->test(); > } > } > > Can you do that? If so is that how you do it? Exactly. Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Post
On Thursday, June 20, 2002, at 12:19 PM, James Drabb wrote: > > I was wondering if there is a setting to make PHP not change the posted > data? For > example I am posting a first and Last name and if I put in O'Hara for > the last name > PHP returns O\'Hara. I would prefer getting just O'Hara back and then > replacing > the ' with '' myself. I need to be able to put the posted data into > MySQL and MS SQL. > MS SQL doesn't like the O\'Hara format. Investigate the gpc_magic_quotes setting in the manual. It's set in your php.ini. You can either work around it using stripslashes() on your GET/POST/COOKIE data, or you can change the setting in php.ini or with a function that changes the setting like ini_set(). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can I be an ASP with PHP?
On Thursday, June 20, 2002, at 02:29 PM, René Fournier wrote: > The idea: In order for Joe User to update text on his web site, he > comes to my "Europa" web site, enters his company name, user ID, > password, and clicks Login, and--voilà--he sees a handsome list of > tables containing the text content of his site--which is pulled from a > MySQL database residing on HIS web site's web host. > > And this is the trick: Can PHP somehow fetch MySQL data over the > Internet? Is this possible? If so, is it necessary for me to resort to > new, unknown technologies like XML or SOAP, or can I do it with PHP > alone? You don't need to use XML. MySQL has no way of "knowing" whether someone is accessing it locally or remotely. You have to specify a domain name or IP address for any client (PHP-based, command-line, or otherwise) that wishes to connect to it and use it, even if that means "localhost". When you specify your database connection parameters, you enter an IP address or domain name for where the database is located. This is normal. The client then uses your web site interface ("Europa") to access their own MySQL database, they make the changes. Now when someone goes to their web site (which also accesses their own MySQL database), they see the updated content. The only thing to worry about is that since they're doing their own hosting of their own stuff, they could hire someone cheaper or learn how to do it themselves and drop their Europa subscription. But I'm sure you've already considered that. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTTP_POST_VARS Question
On Thursday, June 20, 2002, at 02:41 PM, Chris Sechiatano wrote: > Just a simple question about the HTTP_POST_VARS. I know my forms will > work > if I use only the name of the input. Say a text box called FirstName. > I > can just do: > > print "$FirstName"; > > and everything works fine. Why would I want to use > > print $HTTP_POST_VARS["FirstName"]; > > instead? Read the warning box at this page: http://www.php.net/manual/en/language.variables.predefined.php The short version: in PHP 4.1.2 or later you need to either use $_POST, $_GET, etc unless you set register_global = on (it is "off" by default). You don't really ever want to use $HTTP_POST_VARS, $HTTP_GET_VARS, etc unless you are using a version of PHP from before PHP 4.1.0. In which case you might want to use it in combination with turning register_globals = off, to help yourself avoid making bad coding mistakes. It's no substitute for good coding, but it can help. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] insert date with a calendar
= false) { // set the name of the month input from the function parameter $month_form = "\n\n"; // create an array of months $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); // set the counter to 1 b/c we don't want Jan = 0 $i = 1; $monthSelectedAlready = false; $monthPleaseChooseMade = false; // if the client code wants a pleaseChoose, and the default evaluates to empty, // then generate a "Please Choose" option tag. if (!empty($pleaseChooseMsg) && empty($defaultMonth)) { $month_form .= "\t" . $pleaseChooseMsg . "\n"; $monthSelectedAlready = true; $monthPleaseChooseMade = true; } if ($monthPleaseChooseMade == false && !empty($pleaseChooseMsg)) { $month_form .= "\t" . $pleaseChooseMsg . "\n"; } foreach ($months as $monthname) { // if there's a default month and it's equal to the current iteration AND // we haven't already selected a "Please Choose" message, highlight that one if (!empty($defaultMonth) && $defaultMonth == $i && $monthSelectedAlready == false) { $month_form .= "\t{$monthname}\n"; // otherwise it's just a normal option, no highlight } else { $month_form .= "\t{$monthname}\n"; } $i++; } $month_form .= "\n"; // set the name of the day input from the function parameter $day_form = "\n\n"; // create an array of days $days = array(); for ($i = 1; $i < 32; $i++) { $days[] = $i; } $daySelectedAlready = false; $dayPleaseChooseMade = false; // if the client code wants a pleaseChoose, and the default evaluates to empty, // then generate a "Please Choose" option tag. if (!empty($pleaseChooseMsg) && empty($defaultDay)) { $day_form .= "\t" . $pleaseChooseMsg . "\n"; $daySelectedAlready = true; $dayPleaseChooseMade = true; } if ($dayPleaseChooseMade == false && !empty($pleaseChooseMsg)) { $day_form .= "\t" . $pleaseChooseMsg . "\n"; } // loop through the array of days, set a default if appropriate foreach ($days as $dayname) { if (!empty($defaultDay) && $defaultDay == $dayname && $daySelectedAlready == false) { // do I need a way to exclude 'any' from this? ie, add && $defaultDay != 'any' ? $day_form .= "\t{$dayname}\n"; } else { $day_form .= "\t{$dayname}\n"; } } $day_form .= "\n"; // set the name of the year input from the function parameter $year_form = "\n\n"; // create an array of years -- from the function parameter $years = array(); for ($i = $startYear; $i <= ($startYear + $totalYears); $i++) { $years[] = $i; } $yearSelectedAlready = false; $yearPleaseChooseMade = false; // if the client code wants a pleaseChoose, and the default evaluates to empty, // then generate a "Please Choose" option tag. if (!empty($pleaseChooseMsg) && empty($defaultYear)) { $year_form .= "\t" . $pleaseChooseMsg . "\n"; $yearSelectedAlready = true; $yearPleaseChooseMade = true; } if ($yearPleaseChooseMade == false && !empty($pleaseChooseMsg)) { $year_form .= "\t" . $pleaseChooseMsg . "\n"; } // loop through the array of years, set a default if appropriate foreach ($years as $yearname) { if (!empty($defaultYear) && $defaultYear == $yearname) { $year_form .= "\t{$yearname}\n"; } else { $year_form .= "\t{$yearname}\n"; } } $year_form .= "\n"; return $month_form . $day_form . $year_form; } Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] insert date with a calendar
On Friday, June 21, 2002, at 09:27 AM, Erik Price wrote: > * @param string $defaultMonth one- or two-digit number representing a > default month (if empty, defaults to current month + day multiplier) > * @param string $defaultDay one- or two-digit number representing a > default day of the month (if empty, defaults to current day + day > multiplier) > * @param string $defaultYear four-digit number representing a default > year (if empty, defaults to current year + day multiplier) Uh, sorry, I just realized there was some incorrect parameter descriptions in the function I posted. Ignore the parenthesized parts, they are old comments from a previous version of this function -- just erase them. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global variables inside of a function
On Friday, June 21, 2002, at 09:23 AM, Mark McCulligh wrote: > Is there a way to access a session variables or server variables from > inside > a function? > > I have a function and was trying to use $PHP_SELF inside of it. > I get a variable undefined error. > Out side of the function it works fine. > I don't want to parameter pass the global variables to the function, I > know > this would work, but I would have to many variables to pass. This is why superglobals were invented. Use $_SERVER['PHP_SELF'] Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Which costs more: connecting to a DB or accessing the file system?
On Friday, June 21, 2002, at 11:19 AM, mike wrote: > I was reading somewhere (can't remember where) that connecting to a db > is a > pretty costly transaction. DB queries aside, does anyone know of any > benchmarks that demonstrate file access vs. db connections? > > Similarily, while DB queries offer alot of power, would it be cheaper > (faster) to drop simple information that does not require heavy queries > into > a file and access it through the file system? I don't have any stats, but I think it really depends. If you're executing a really complex query that uses like six JOINs and eight WHERE clauses, then the bottleneck is the DB and not the DB access itself, so it would probably be quicker to have this information ready in a file (or even better, cached in memory somehow, though I have no experience doing this). But I believe that with a simpler DB query, a DB access is faster than a file read. Here's something that turned up in Google... http://phplens.com/lens/php-book/optimizing-debugging-php.php Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] any reason why mail() returns a false value?
FRUSTRATION. I figured it was time to upgrade PHP anyway since I was using 4.1.2 and then there's that Apache security problem, so I upgraded that too. And my sendmail problem is still present -- every time I try to call the "mail()" function, even with the simplest of arguments (the first three required arguments, all three of them simple string literals: mail('[EMAIL PROTECTED]', 'SubjectString', 'BodyText')), it fails. No email is sent, the return value of the function, when cast to integer, is zero, and I have thoroughly tested that sendmail works just fine. It is a RedHat 7.2 server, if that matters (though I don't think it does). I have done all of my compiling as root, and /usr/sbin/sendmail was definitely in my PATH. If I had any money, I would PAY for someone to explain to me what is going wrong. Thank you in advance if you can help me. Sincerely, Erik Price Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] any reason why mail() returns a false value?
Ed, thanks for taking a look at this: [eprice@media eprice]$ less public_html/testmail.php a mail Test Now, hopefully your message has been sent."; print "The return value of mail() is " . (int)$return . ".\n"; ?> The results I get are: Now, hopefully your message has been sent.The return value of mail() is 0. My path_to_sendmail is confirmed to be correct, and again, I have tested sendmail -- it works fine from the command line. It's executable by all users, so my Apache user shouldn't have a hard time executing it. There's just no explanation! I've even pointed my path_to_sendmail to an executable shell script that prints a confirmation message if it is executed, and the mail() function has the exact same effect if I do this. Gratefully, Erik On Friday, June 21, 2002, at 12:56 PM, Lazor, Ed wrote: > Please send code generating the problem. > >> -Original Message- >> my sendmail problem is still present -- every time I try to call the >> "mail()" function, even with the simplest of arguments (the >> first three >> required arguments, all three of them simple string literals: >> mail('[EMAIL PROTECTED]', 'SubjectString', 'BodyText')), it fails. >> >> No email is sent, the return value of the function, when cast to >> integer, is zero, and I have thoroughly tested that sendmail >> works just >> fine. It is a RedHat 7.2 server, if that matters (though I >> don't think >> it does). I have done all of my compiling as root, and >> /usr/sbin/sendmail was definitely in my PATH. > > * > *** > This message is intended for the sole use of the individual and entity > to > whom it is addressed, and may contain information that is privileged, > confidential and exempt from disclosure under applicable law. If you > are > not the intended addressee, nor authorized to receive for the intended > addressee, you are hereby notified that you may not use, copy, disclose > or > distribute to anyone the message or any information contained in the > message. If you have received this message in error, please immediately > advise the sender by reply email and delete the message. Thank you very > much. > > Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 4.2
On Sunday, June 23, 2002, at 09:06 AM, Pekka Saarinen wrote: > Most virtual server users have no means to set PHP.INI to their liking > so changes like that should be done in longer time span to let > developers update the software _before_ changes in PHP happen. What about ini_set() ? http://www.php.net/manual/en/function.ini-set.php ---- Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whos online at the moment in PHP
On Sunday, June 23, 2002, at 09:53 AM, Pag wrote: > Is it possible to code in PHP a small indicator on a site saying > how many people are viewing that page at the moment? > Sorry if its a silly question, but i am a newbie at PHP. If it is, > could you point me in the good direction? i mean, some function or > something. Sorry, can't be done. People aren't really "online" when they are using a web browser. They request a page, and it gets sent to them, and the web server forgets about them. Unless the web server logged their request, but then the web server has no way of knowing when the user "stops" looking at the page, so... you get the picture. You'd have to write a Java applet or something that can maintain state. HTTP can't do this. Unless you're really creative and you use JavaScript and sessions (and even then it won't be very reliable). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] === and @
On Sunday, June 23, 2002, at 10:46 PM, Phil Schwarzmann wrote: > What exactly happens when you put three equal-signs together instead of > just one or two? I've seen this in other people's code, then search > php.net and found nothing. PHP does dynamic typing. So the following returns TRUE if ("1" == 1) even though the first value is a string and the second value is an integer. You can force PHP to check for the same type by using three equal-signs, so that the above would return FALSE but either of the two below would return TRUE: if ("1" === "1") if (1 === 1) > Also, what happens when you put a @ thingy in front of a function? Does > it surpress the errors? Yes. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to remove item from cart
On Sunday, June 23, 2002, at 09:30 PM, Vicki wrote: > If you can suggest code that works, that would be great, or at least > point me in the right direction if I'm on the wrong track with > checkboxes. If you haven't noticed already, I'm very, very new to PHP > and haven't quite got the hang of it yet. :=) Someone else mentioned the "empty()" language construct. Learn this and use it everywhere. I find that it is probably one of my most-often used tricks to evaluate user input of any kind, especially checkboxes and radio buttons. The reason why is because if you use "if ($_POST['varname'])" or "if (isset($_POST['varname']))", you're testing to see if the variable was ever set. With HTML forms, they may in fact have been set but have no values. Using empty() will test to see if they evaluate to false (such as if they contain an empty string, which is what happens when someone submits a form but doesn't actually put some data into a certain input), and that is a reliable way to test for changes. Also, I have a shopping-cart-like feature on my site. I store my "purchased" objects in an array. One thing that I learned the hard way is that if you use unset() to remove items from this array, you will end up with empty array elements. If you need to re-order the array (to put the indexes into a sequential order once again), you can do something like this: array_push($array, 'dummy_value'); unset($array[$index_to_unset]); array_pop($array); Because using array_pop() will re-index the array. Much thanks to Nathan for that tip. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] real time php
On Monday, June 24, 2002, at 10:04 AM, adi wrote: > How to make a function for refreshing values in php pages, without > pressing Refresh button. What must i read? There's a meta tag that will auto-refresh the page after a specified number of seconds. That will work. But you can't re-populate the data in the page using PHP. Remember, PHP has generated an HTML document and sent it to the user's browser. That is all. If you are creative, you can use JavaScript to solve the problem, but it will require some kind of communication with the web server, and won't work if the user doesn't have the right implementation of JavaScript. That can be a headache. or you can write a Java applet (actually for this kind of task I recommend this). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with PHP_SELF
On Monday, June 24, 2002, at 10:42 AM, DoL wrote: > Can anyone advice what did I missed here? > Would this have anything to do with php or/and apache configuration? Is it possible that your php.ini file is configured for register_globals = off ? If so, you should use: $_SERVER['PHP_SELF'] instead of $PHP_SELF. Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 4.2
On Monday, June 24, 2002, at 10:55 AM, Jason Wong wrote: > There are quite a few config settings which cannot be altered using > ini_set(), > register_globals being one of them, although that can be set using > .htaccess > files. I see. I must have misread this page: http://www.php.net/manual/en/function.ini-set.php The terms PHP_INI_SYSTEM and PHP_INI_ALL aren't totally clear in the right-hand column titled "changeable". Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Auto logout?
On Monday, June 24, 2002, at 11:14 AM, Hawk wrote: > I have a login, and when users are logged on, it should show in some > way on > the page, that's not the problem, it is to show that they are logged off > when they are, often people forget to press the logout button, and the > mysql > database is unchanged, saying they are still logged on, how can I do so > it > logs out when a user leaves the page, if the page is closed or something > like that, need suggestions, sorry for my currently bad english, but > I'll > blame the heat ;) Hawk, Have a read of the following thread from this weekend: http://marc.theaimsgroup.com/?l=php- general&r=1&w=2&q=b&s=Whos+online+at+the+moment+in+PHP It discusses some of the issues involved in this. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function definition causing problems?
On Monday, June 24, 2002, at 12:15 PM, Johnson, Kirk wrote: > When you echo out an array element, the name needs to be enclosed in > curlies, e.g., > > echo {$_SERVER['PHP_SELF']} I think that this is only important when using an associative array element reference within certain kinds of quotes. Like this: // this won't work b/c of quoting issues echo "This script is called $_SERVER["PHP_SELF"]"; // this should work fine IIRC echo "This script is called $_SERVER['PHP_SELF']"; // this should also work if for some reason you needed // to use double quotes within the array element reference // (to interpolate a variable, for instance) echo "This script is called {$_SERVER["PHP_SELF"]}"; // and this is the same thing really echo "This script is called ${_SERVER["PHP_SELF"]}"; Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function definition causing problems?
On Monday, June 24, 2002, at 01:30 PM, Ford, Mike [LSS] wrote: > You can use: > >echo "This script is called {$_SERVER['PHP_SELF']}"; >echo "This script is called ${_SERVER['PHP_SELF']}"; >echo "This script is called $_SERVER[PHP_SELF]"; > > or even > >echo "This script is called " . $_SERVER['PHP_SELF']; Oh. Well, thanks for clarifying -- I always use the concat (last) method myself, but this settles an incorrect assumption I'd been carrying around for months. You're batting two for two today. ;) Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Lost, need help debuggin....
> If you don't find it, look for a php-ini.dist or php-ini.recommended in > the > php folder. > > Modify one of those to your needs and save it as php.ini. I don't know > where > it would go in a Mac, though... ?? Open Terminal.app and type sudo find / -name 'php.ini' -print and enter your password when it asks for your password. Be patient as it searches, you'll get no visual confirmation that the search is running until it's done or until it finds something. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Lost, need help debuggin....
On Monday, June 24, 2002, at 03:51 PM, Erik Price wrote: > sudo find / -name 'php.ini' -print Clarification: substitute the search string with 'php-ini.dist' if you haven't yet configured it. Note that Macs, although they ship with PHP pre-installed, are missing this file and you should probably download it from the PHP source tree, if you're using the pre-installed PHP. (If you've compiled your own, then you have it in the 'lib' directory of wherever you installed PHP, such as /usr/local/lib/php-ini.dist). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] appending to XML file before closing tag
On Tuesday, June 25, 2002, at 09:31 AM, William S. wrote: > I know I need to introduce: fread() and fseek(). > but not sure how to put it all together. If you know for a fact that the ending tag for each file is consistent and always that same tag, here's an idea. Determine or specify the length of the ending tag (in other words "" would be a length of 7 [characters]). Now move your file pointer to (file's total characters - length) so that it is immediately before the ending tag. Append your data, then manually append the ending tag. If you will deal with varying ending tags, then you'll have to come up with a creative method for capturing them and storing them, then dynamically determining their length and do the same thing, then append the ending tag (whatever it may be). I would use regexes to do this part. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] char function
On Tuesday, June 25, 2002, at 06:23 AM, Leo wrote: > i want a logical function (true or false) that search a character into a > string.(like indexOf() in javascript) > example: i want to find char '@ ' in the string [EMAIL PROTECTED] $str = '[EMAIL PROTECTED]'; if (preg_match('/@/', $str)) { print "$str does contain the '@' symbol.\n"; } Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [php] How to get request url string and server hostname
On Tuesday, June 25, 2002, at 02:56 PM, Harriet Xing wrote: > Would anyone know how to get the http request url string in php? > i.e., if the request is "http://www.myserver.com/test.php?param1=123";, > how can I obtain this string in test.php? $request = "http://"; . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']; However, I don't like using $_SERVER['QUERY_STRING'] because if there are empty GET variables, it grabs them. So, if you prefer, you can do this: $getVarsArr = array(); foreach ($_GET as $getVarName => $getVarVal) { $getVars[] = $getVarName . "=" . $getVarVal; } $getVarsStr = implode("&", $getVars); $request = "http://"; . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "?" . $getVarsStr; Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [php] How to get request url string and server hostname
On Tuesday, June 25, 2002, at 03:22 PM, Erik Price wrote: > However, I don't like using $_SERVER['QUERY_STRING'] because if there > are empty GET variables, it grabs them. So, if you prefer, you can do > this: > > $getVarsArr = array(); > foreach ($_GET as $getVarName => $getVarVal) { > $getVars[] = $getVarName . "=" . $getVarVal; > } > $getVarsStr = implode("&", $getVars); > $request = "http://"; . $_SERVER['HTTP_HOST'] . "/" . > $_SERVER['PHP_SELF'] . "?" . $getVarsStr; Doh, I forgot the part where you test for empty -- amend the above in the following fashion: $getVarsArr = array(); foreach ($_GET as $getVarName => $getVarVal) { if (!empty($getVarVal)) { $getVars[] = $getVarName . "=" . $getVarVal; } } $getVarsStr = implode("&", $getVars); $request = "http://"; . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "?" . $getVarsStr; Why would you care if there were empty GET vars? Well, if you had a big search engine or some other form where the user can specify a bunch of criteria or just a little bit, it's up to you. It's nice if you have to grab the GET data for whatever reason (repopulating links, etc) and you don't waste time with huge querystrings made up of mostly-empty variables. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I changed my root password and now can't connect to MySQL
On Tuesday, June 25, 2002, at 03:27 PM, Phil Schwarzmann wrote: > Now, whenever my script runs a MySQL command, I get this error > > Warning: MySQL Connection Failed: Access denied for user: 'root@MY_PC' > (Using password: YES) in C:\...\dbconnect.inc on line 3 > Cannot connect to The Database. You need to grant privileges to log in as root remotely, which is probably not recommended. Basically a GRANT statement that lets people access MySQL as root from your IP address. Better to create a new user (such as "phpuser" or something) and enable that one instead. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security problem?
On Tuesday, June 25, 2002, at 03:46 PM, Peter wrote: > When you have the standard > > $link = mysql_connect("localhost","username","secretpassword"); > > Would it not be possible for someone to use PHP from another server to > download your source and find out your MySQL details including password? Yes. If they have access to the source, they can see these values. If they don't have some way of seeing those files, though, they won't be able to do it. For this reason it is a good idea to make sure that no one except you and the user that the webserver runs as can read your files. For instance, all my files are actually readable to all (their mode is 644), except for one. This one file is readable only to me and members the "apache" group, and it contains all of the database connection parameters. Of course, the only member of the "apache" group is the "apache" user that the web server runs as, so no one else will be reading this file. It's a luxury of having root access on my server, since this is pretty difficult to do without a root user (catch 22 -- how do you change the file to the "apache" group unless you are a member of the "apache" group, but if you are a member of the "apache" group then you can see all of the "protected" files in that group). Also I have a directive that prevents Apache from serving any file with ".inc" suffix, and this file does, so Apache (hopefully) won't serve this data to the world via port 80. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Menu Selections Dynamic from a Database
On Tuesday, June 25, 2002, at 04:01 PM, Phillip S. Baker wrote: > Yes I knew it was Javascript code, but I also thought PHP was needed to > get the values from the DB. > Either case I do need help with what the code might look like. Okay, here it is... kinda complicated, but using this theory you should be able to do it: You need to populate an HTML listbox based on DB data. Make sure your SELECT query gets both the primary key of each record and the actual name that you want to appear in the listbox. Dynamically generate the listbox in the normal way, by using the primary key as the "value" attribute of each tag and using the other column value as the CDATA contents of the option element, like this: " . $row['name'] . "\n"; } ?> You will have something like this in $output: Yoda Ben Annikin Luke The "controlOther()" is a JavaScript function that you will write in a moment. Anyway, you now have a listbox with values that exactly match your JavaScript array. What you do next is you assign a name to the select tag which holds the listbox values, and place the listbox values into the select tag: " . $output . "\n"; ?> And of course you need to put your select tag into a named form (the names are important for the JavaScript!): BLAH BLAH BLAH other inputs can go here " . $selectTag . " "; ?> Okay! Now you have your form, named "choosejedi", your input, named "jedimasters", and a listbox filled with name/value pairs. Your intended effect is to allow one listbox's actions to control another listbox's data. For this, you need to write a JavaScript function that controls the other listbox. \n"; ?> You can see what this function does -- it takes the value of the argument passed to it and executes certain other code according to the switch() statement. I don't have time to actually write out possible code for these cases, so I just put "" or "" etc (it's all a hypothetical example anyway). You will want to have already generated this data from the DB using PHP anyway, so you would just plug in a few variables here (whose values are defined earlier in the script). The point is that every time someone makes a selection in the listbox, they will trigger the ONSELECT event handler, which calls the "controlOther()" JavaScript function. The value passed to controlOther() tells ANOTHER listbox on the page what it should be populated with, based on the switch() statement. You need to have names for all your forms and your inputs so that you can refer to them using the JavaScript Document Object Model... in other words, your controlling code would look something like document.choosejedis.jedimasters.value refers to the selected value in the main listbox, and can be used to perform actions on other listboxes. ANYWAY... this got way longer than I intended. Basically, I haven't tested any of the above but in theory it should work, but be sure to do mad browser detection so you can be sure that it'll work, etc. I personally wouldn't even bother, this kind of coding is pretty technical and you may as well just do it in PHP in case the user doesn't have JS turned on. I think it's a lot easier to do it in PHP too. Sure, the user will have to submit the page to update the new listbox, but... not so hard, eh? Essentially it boils down to this pseudocode: 1. use PHP to dynamically generate a main listbox to control the next listbox 2. use PHP to dynamically generate possible values for the secondary listbox (I would just throw 'em in arrays) 3. determine which array should populate the second listbox based on the input in the first listbox using JavaScript event handlers in the first listbox HTH, Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] More on removing item from cart
On Tuesday, June 25, 2002, at 04:28 PM, Vicki wrote: > I have a shopping cart array $cart, with $artID as its key ($artID is an > integer). $cart is set as a session variable. The cart prints to the > browser with checkboxes next to each article and instructions to uncheck > the checkbox and click on the "Save Changes" button to remove items from > the cart. (This is the part that doesn't work.) The checkbox input has > "NAME = checkbox[$artID] VALUE = yes", and there is a hidden input with > "NAME = save VALUE = true" that are passed when the form is submitted. Before we even discuss the logic of your code, I need you to confirm that you are 1) properly quoting your attributes (some browsers will react badly if you don't) 2) not using the actual value "checkbox[$artID]" in your code With "2", in other words I am making sure you are not trying to pass an array element name via HTTP. The name of any HTML form input needs to be made up of letters, underscores, and numbers, IIRC. As far as the logic goes, forgive me for being blunt but your explanation is confusing me and I can't really follow it. If you have neat, commented code, post the relevant part of it and hopefully someone can come up with some good input (I'll take a stab). Basically checkboxes are tricky, because if a checkbox is NOT checked, and then the form is submitted, an empty variable name is NOT sent... only checked boxes are sent. So you need to check for the presence of variables if you are going to unset() the unchecked boxes, or determine the unchecked values based on what is NOT checked, etc. Good luck Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: One more 'Headers Already Sent' error. :-(
On Tuesday, June 25, 2002, at 06:07 PM, Brad Melendy wrote: > Well, I have traced this down to line 4 in the following code > 'include("header.html");' which just includes my navigation bar. If I > comment it out, everything works great, if I leave it in, I get the > error > Headers Already Sent. The file it purely html. What could be the > problem?? > Thanks in advance! You want this script to redirect twice? Or do you just want it to redirect the first time, but have the second header() function be called if the first one doesn't? Then you should call exit() after the first header() function to keep the rest of the script from executing. This is also generally a good practice after a header('Location: ') call because the user-agent doesn't HAVE to respect the header and redirect, so it protects your stuff. Always feature an exit() with a header-based redirect. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing Form Values
On Tuesday, June 25, 2002, at 06:56 PM, Phillip S. Baker wrote: > When the form is submitted I want to values passed to a pop-up window. > I am aware of the need for Javascript for the pop-up window, but how do > I get the values from the form passed to the new window so I can use > them in further scripts. > I can write the javascript to do the popup window and use the onSubmit > command, but I cannot figure out how to pass the values with a regular > submit button. > Thanks Pass them along the querystring, so that when the JavaScript popup window opens and it goes to a certain page, those values are part of that URL. As GET variables. // Your PHP vars: $var1 = 'Metroid'; $var2 = 'Metal Gear'; // Create a querystring: $PHPqueryString = "var1=" . $var1 . "&var2=" . $var2; // echo the browser string for the popup: print "Popup!\n"; // here's your JavaScript function function openPopup(queryString) { var detailwindow = window.open('./target.php?' + queryString, 'windowname', 'toolbar=no,directories=no, status=no,menubar=no,resizable=yes, copyhistory=no,scrollbars=yes, width=500,height=300'); detailwindow.moveTo('150', '150'); } Now in your new script you can access these GET vars from PHP or from JS! Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Security problem?
On Tuesday, June 25, 2002, at 08:26 PM, Analysis & Solutions wrote: > I usually run PHP as CGI. My secure files are kept in a directory > that's > not under the */docroot. Thus, they can't be gotten to through the web > server at all. Plus, the secure files are chmoded 600 (which means they > can be read/written only by the owner). Thereby, the only user on the > server who can read them is me. Tradeoff, huh? If I understand it correctly, you can't keep the files outside the docroot if you're using mod_php b/c the web server itself is what fetches the file (therefore it needs to be in the docroot). But mod_php is faster than CGI PHP and can handle more simultaneous requests. Right? Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] appending to XML file before closing tag
On Tuesday, June 25, 2002, at 08:42 PM, Brian White wrote: > I was actually thinking about this the other > day - every now and again I find my self > yearning for SGML, where you could have > just declared the wrapping element "end > tag omissable", and then you would never > have to worry about it - basically > the end of the file would imply the > existence of the end tag (sigh ) Yes, but that makes parsing very difficult -- if you're expecting to find a closing tag, it should be there. You'd have to write a special set of XML-handling functions or a special library to cover this unique breach of the XML rules, since most XML modules (for Perl, PHP, Python, Java, whatever) expect well-formed documents. XML is pretty verbose, yes, but the rewards of this are consistency -- as long as the document is well-formed, it should be pretty easy to extract the data from it without writing special code to handle these kinds of exceptions. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: MySQL Problem with PHP
On Wednesday, June 26, 2002, at 08:58 AM, John Holmes wrote: >> I just preg_replace("/\'/","\'",$text) and all was good :o) > > That's what addslashes() is for. It handles single and double quotes, > backslashes, and nulls, so you won't have any problems... Plus IIRC it's a C extension so it'll run faster anyway. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seperating presentation from logic
On Wednesday, June 26, 2002, at 09:05 AM, John Holmes wrote: > I disagree. Maybe I'm just not getting it, or understanding the "FULL > POWER" of xml/xslt. It just seems like it's adding in an additional > layer that you don't need. It seems so dependent on browser versions, > and parser versions, etc. Just make a plain HTML template and a small > template parsing script to insert the variables you need. Pattemplate is > pretty close to XSL, but I haven't seen any speed comparisons on it. Yeah, but what if you want to output to a format other than HTML? For instance you want to generate a PDF invoice, which is emailed to the user, but you also want to display that invoice to the user? Should you have two separate files/sources of data? You could have one XML file, and use XSL to make an HTML document which appears in the user's browser and a PDF which is emailed to them. The point of XML is to look beyond the web browser as a point where the user needs data. PDAs would benefit from non-HTML formatted stuff (too small a screen for most web pages), cell phones have their hardly-used WML, there are tons of different print formats like PDF or PostScript, plus alternative formats like troff (for man pages) and POD (for Perl manpages) and others. XSLT lets you output from one source file to any desired format. If you need versatility in the output of your data, XML can really help you. Plus, it doesn't depend on browser version if that's what you're worried about -- it can be done server-side: use PHP to perform the transformation before it gets to the user if it's going to their browser. That's why some XML-based sites let you choose whether to view the page in HTML or XML (so that if you want to use a spider or script to parse the data on the web page instead of looking at it in a browser, you can do that much more easily with the XML formatted output than the HTML formatted output). Later on down the road, when (hopefully) all browsers incorporate an XSLT processor, the burden of performing the transformation can be handled by the client. Not that client-side technology has been very successful at standardizing, in consideration of different JavaScript implementations, CSS implementations, and even Java Virtual Machines (witness Microsoft consistently refuse to ship a decent JVM with their OS, even though they are freely available from the Sun web site). That's why server side stuff like PHP will probably always be invaluable. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Web Services
On Wednesday, June 26, 2002, at 10:49 AM, Laurent Drouet wrote: > I would like to know if there is a way to request data from a web > services > for example http://glkev.net.innerhost.com/glkev_ws/Currencyws.asmx > using php without java ? If you know the web services API, you just send your request. It shouldn't matter whether you're using Java, PHP, Python, even VB or even Telnet to generate your request -- most web services accept an HTTP POST message consisting of XML code which is used to perform some kind of action. There are two things you can do -- either use the cURL functions (your PHP binary must be compiled with cURL enabled to do this), which give you an advanced set of URL accesses, or open a socket to the remote machine with the web service and send a stream of POST data that way. You can use Rasmus Lerdorf's "postToHost" function (this may as well just become a PHP function, it gets referenced so much), which I have appended to this message. Either way, just generate your XML string and fire it at the remote machine. You will need to write code to handle the response, obviously. # === # PostToHost($host, $path, $data_to_send) # --- # "It is a trivial little function." # -Rasmus # === function PostToHost($host, $path, $data_to_send) { $fp = fsockopen($host,80); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: " . strlen($data_to_send) . "\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, $data_to_send); while(!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OOP assistance request
Hi, I'm making this request for help because my experience with object oriented programming is very limited. I'd like to describe my situation and then ask a question at the end of it, any comments or input are very appreciated. My application needs to keep track of different kinds of projects, and display different attributes depending on what kind of project it is. Therefore, I have written a base class called Project. The four kinds of projects are PrintProjects, DesignProjects, WebProjects, and PhotoProjects. Each of these extend the Project class, so they are child classes. I intend to write my code to use polymorphism so that a single method call, $object->display(), will generate the appropriate output depending on which child class it is being called upon. So really, the Project class is just an abstract class and is not really intended to be instantiated, but PHP doesn't really enforce a difference between abstract classes and true classes. And each project has a corresponding record in a MySQL database, so I have a convenient primary key for every Project object (regardless of what kind of project it is). HOWEVER -- Because this is PHP/HTTP and not Java, there is no true "state". So the way that I instantiate a Project is by passing the primary key of the object as an argument to the constructor of the Project. The constructor can then "flesh out" the object as needed, and ideally there will be different "flesh out" code depending on the type of object. My problem is that I have no way to know which type of object to instantiate in advance -- all I have is this primary key. Using the primary key to instantiate an object, I can extract the ProjectType primary key, and then I could instantiate a new object of the appropriate type, but then I'd have two objects (and that seems like a lot of overhead). I'd rather just have the client code instantiate the right type of object from the beginning. Is there a way to convert a Project object into a PrintProject object -- such as casting it? In other words, I'd like my client code to look like: $obj = new Project('87633'); $type = $obj->getProjectType(); if ($type == '1') { $obj = (PrintProject)$obj; // re-cast the Project into a PrintProject } elseif ($type == '2') { $obj = (DesignProject)$obj; // re-cast the Project into a DesignProject // etc } $obj->display();// now the object will call the appropriate // overriding method because the object is // now of the appropriate subtype Is that possible in PHP Namely, the casting above? Or does my client code need to be able to figure out which type of project it is (say, from the DB) and then use this to determine which object type to instantiate? Thanks very much, Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compiling PHP with XML????
On Wednesday, June 26, 2002, at 11:57 AM, Scott Fletcher wrote: > I looked in the "./configure --help" for the xml support. It didn't > say but > show some options such as disabling xml, using xml with different > stuffs. > Nothing is being mentioned about enabling xml or something. So, is xml > in > php supported automatically? Yes. Since 4.1.x at least. But for XSLT you need to get expat and Sablotron and link them into the compile (with the appropriate ./configure options). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] dynamically creating variable names
On Wednesday, June 26, 2002, at 01:04 PM, Lee P Reilly wrote: > Can someone tell me if it's possible to create variable names from > varaible names? I could work around this problem using some if/else > statements, but I'm interested to see if there's another solution. Just try it. for ($i = 0; $i < 10; $i++) { $var{$i} = $i + 6; echo "\$var$i == " . $var$i . "\n"; } $var0 = 6 $var1 = 7 $var2 = 8 $var3 = 9 $var4 = 10 $var5 = 11 $var6 = 12 $var7 = 13 $var8 = 14 $var9 = 15 Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP does not work??
On Wednesday, June 26, 2002, at 01:20 PM, Scott Fletcher wrote: > When I use the hyperlink, "test.php?data=yes" and I go to this page, > test.php but there is no data in this variable, $data. So, the web > page I > have, most of them are all thrown off becuase of this. I use PHP > version > 4.2.1. Is there a bug in this PHP version??? Or some changes in PHP > that > I'm not aware of? Let me know! Use $_GET['data'], not $data. Or turn register_globals = on in your php.ini. Get to know your php.ini, and read the release notes for any software you upgrade -- this is mentioned in the PHP 4.1.x release notes if you want to read them for yourself. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server security
On Wednesday, June 26, 2002, at 01:33 PM, Phil Schwarzmann wrote: > What else can I do to make this server secure? What is this SSL > business all about? Any extra programs I should add that might help? Read this from beginning to end. Then you will know what questions you need to ask to make yours system more secure. http://www.w3.org/Security/Faq/ Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP does not work??
On Wednesday, June 26, 2002, at 02:13 PM, Scott Fletcher wrote: > I'm using UNIX, not windows, so there is no php.ini in UNIX. Sorry, don't take offense if I ask if you've been living under a rock -- I only use Linux, and there is definitely a php.ini file that you use. I put mine in /usr/local/lib/ . If you follow the source install instructions, you will see that the last step is: $ cp php.ini-dist /usr/local/lib/php.ini Yep, that means you're supposed to copy php.ini-dist to a dir on your server. This is your configuration file, where register_globals and a million other configuration directives are decided... ? Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] passing variable arguments from
On Wednesday, June 26, 2002, at 02:51 PM, Haddad Said wrote: > Hi, i am having a problem passing variables from a drop down menu in a > form; > > > > one > two > You should do it like this (be sure to properly quote your attributes, and use the 'value' attribute of the 'option' tag): print " One Two \n"; In the "test.php" page, the selected value will be found in the $_POST['example'] variable. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] diffrance : require(); a file from localhost and from a domain.
On Wednesday, June 26, 2002, at 03:19 PM, <[EMAIL PROTECTED]> wrote: > tecnically whats the diffrance if I do: > > require("http://localhost/image.gif";); > or > require("http://www.domain.com/image.gif";); ? The first one requires the file at "localhost/image.gif", and the second one requires the file at "www.domain.com/image.gif". Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP does not work??
On Wednesday, June 26, 2002, at 02:56 PM, Scott Fletcher wrote: > I tried that and it worked. I have > one question, what about the hyperlink? People will see the option in > the > hyperlink. You know. Is there a way around it to hid that in the > hyperlink? If by "hyperlink" you mean the URL in the URL bar of their browser, correct -- people will see it. That GET data is part of the URL, sort of. Most browsers will not display POST data to their users (easily) but it's never truly "hidden" from view. Any data that your users are sending to you, whether it's GET, POST, or COOKIE, is data that they can see. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP does not work??
On Wednesday, June 26, 2002, at 02:37 PM, Scott Fletcher wrote: > I didn't know that. Thanks for the info. I think it would be best > that I > not use php.ini. On the contrary, I think it would be best if you read through it and read about it at http://www.php.net/manual/en/configuration.php . Putting it off will only cause you trouble in the long run. > I can write the script to register the variable. What would be a demo > script that would work? I'm having a little trouble understanding that > on > the php.net website. Most of the script that use global variables came > from > hyperlinks. I have no form method like "post" or "get". If it doesn't have "post" or "get", then your data is probably in the $_GET array. But you should always use the "method" attribute of the "form" tag. > I have one website that use session. Like session_start(), > session_register(), etc. How would this be affected and what is the > work > around to this one. You now refer to a session variable as $_SESSION['variablename']. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java Pop UP...
On Wednesday, June 26, 2002, at 03:37 PM, Doug Coning wrote: > I have a php page that return rows from a database. I then have an href > link to the individual thread as such: > > target='_blank'>". > > > This works, it opens a new window which has the detailed information > needed. > However, how would I write java code into this to force it to open the > window at 300 by 255? I know the java code for this is as follows: > > onclick="MM_openBrWindow('73things_thread.php','Thread','scrollbars=yes,widt > h=300,height=255') > > How do I merge the java code into PHP? Make sure the function is defined somewhere above, between
[PHP] casting user-defined objects
I have been playing around and am unable to explicitly cast an object instance from one user-defined type to another, using the traditional type-casting syntax nor with the settype() function. I feel like I should mention this as an annotation in the man page, but I was hoping someone could steer me right if I'm wrong here. The following code doesn't work: class Apple { // some atts and meths function display() {// do something } } class Orange { // some atts and meths function display() {// do something } } // this part works fine $fruit = new Apple; $fruit->display(); // this part doesn't work like you think it would $newFruit = (Orange)$fruit; $newFruit->display(); The confusing thing is that this page http://www.php.net/manual/en/language.types.type-juggling.php actually does feature casting to objects, but I am unsure of what purpose the "object" type reference has. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Another Pop-Up problem..
On Wednesday, June 26, 2002, at 08:39 PM, Doug Coning wrote: > I've got it to work now where it will pop up a window. However, now it > returns the same record each time. So which ever record you click > first, it > will bring that window up for each item. > > How do I reset or clear out the value so that when you click a different > link it brings up the proper record. You can see what I mean by > visiting > the code at: http://www.coning.com/phptest/73things_view5.php. Doug, I took a look at your page. The problem doesn't appear to be with your JavaScript, it seems to be a problem with your PHP. Try directly opening the following links in your browser and you'll see what I mean: http://www.coning.com/phptest/73things_thread.php?threadID=13 http://www.coning.com/phptest/73things_thread.php?threadID=14 http://www.coning.com/phptest/73things_thread.php?threadID=15 Even though the threadID GET value is different in each one, the same data is coming up. So you need to check your back end code. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php