Search found 20 matches

by TJ
Sun Nov 06, 2005 2:11 pm
Forum: Code Snippets
Topic: IPv4 format validation
Replies: 10
Views: 15991

Using ip2long() is cheating though :lol: I was enjoying trying to write the code that usually sits under the hood, rather than looking for another way to do it in PHP. Its fascinating (to me at least) that what looks so simple can take so much thought and be so intriguing. Anyhow it gave me a nice h...
by TJ
Sun Nov 06, 2005 9:15 am
Forum: PHP - Code
Topic: Keeping html files private
Replies: 3
Views: 529

As the pages that can be accessed directly are HTML, PHP doesn't get involved so any security measures you take on those need to be done from the HTTP server. Simple basic authorisation using .htaccess (on Linux) or ACLs on Windows (removing the read permission for the IUSR_MACHINENAME for .HTM/HTML...
by TJ
Sun Nov 06, 2005 2:35 am
Forum: PHP - Code
Topic: Problems with classes
Replies: 1
Views: 148

You're getting the C++ dot operator and the PHP member-selector mixed up. On one line you use the correct format, but then in the echo you use C++ format, which is interpreted as the PHP dot operator for concatenating strings. $currentUser->password = "test"; echo $currentUser -> password ...
by TJ
Sun Nov 06, 2005 1:50 am
Forum: Code Snippets
Topic: IPv4 format validation
Replies: 10
Views: 15991

This got me to thinking about the way we often forget that the various representations of an IP address are all just ways of writing a decimal value that can be up to 4294967295 (largest unsigned value in 32 bits). I sometimes like confusing friends by giving them addresses like this to visit http:/...
by TJ
Sat Nov 05, 2005 11:41 pm
Forum: Code Snippets
Topic: Prettying XML output
Replies: 3
Views: 12620

Ahhh... ta very muchly... after 36-hours non-stop coding all the forums tend to look alike :lol:
by TJ
Sat Nov 05, 2005 5:36 pm
Forum: Code Snippets
Topic: Prettying XML output
Replies: 3
Views: 12620

Prettying XML output

I just had need to pretty-format the output of DOMDocument->saveXML() for ease of reading, which comes as a string with no linefeeds or indentation of the XML. I thought I'd share the function in case others have need of something similar in the future; it took a while to get it settled, and it migh...
by TJ
Sat Nov 05, 2005 1:55 pm
Forum: PHP - Code
Topic: dynamically passing comparison operator
Replies: 1
Views: 180

Use an eval() on strlen($input_string) $comparison_operator $length so it looks something like this (not tested):

Code: Select all

eval("\$result = ".strlen($input_string)." $comparision_operator $length");
if($result) {
 $valid = 1;
See PHP manual: eval
by TJ
Sat Nov 05, 2005 11:35 am
Forum: PHP - Code
Topic: Finding part of a Variable..
Replies: 4
Views: 800

The kind of functionality you describe is commonly called browser sniffing or browser caps aka browser capabilities . There'll be libraries around that do that to varying degrees of sophistication. I've written my own limited code for detecting a specific (non-web) client using a regular expression,...
by TJ
Fri Nov 04, 2005 6:36 pm
Forum: PHP - Code
Topic: Better way to do it without using IDs?
Replies: 23
Views: 5236

You don't actually need to know the row numbers. Recall that the SQL LIMIT statement takes two parameters: start, count So given a recordset 'R' returned from "SELECT * FROM table"; "SELECT * FROM table LIMIT 1, 10" will give you records 1 through 10 "SELECT * from table LIM...
by TJ
Fri Nov 04, 2005 6:13 pm
Forum: PHP - Code
Topic: Extending DOMElement *and* DOMDocument in PHP5?
Replies: 4
Views: 506

Yes, thats the way to do it. Let's just hope developers are disciplined enough to implement that design template in modular classes. I've had a discussion with the PHP developers today about these issues ( Bug 35104 ), and hopefully the documentation will have strong recommendations with a design te...
by TJ
Fri Nov 04, 2005 8:57 am
Forum: PHP - Code
Topic: Extending DOMElement *and* DOMDocument in PHP5?
Replies: 4
Views: 506

Unfortunately the work-around has severe drawbacks. Primarily because importNode() returns an object of the super class (DOMElement) rather than of the class passed to it - KMLElement. This is worse in that the new object doesn't have the functionality given it when it extended DOMElement. This appe...
by TJ
Fri Nov 04, 2005 7:44 am
Forum: PHP - Code
Topic: Got an error from mysqli_num_rows when trying to do a query.
Replies: 5
Views: 374

Try checking that mysqli_query() has returned a result. // Query: $myQuery = "select * from authorized_users where name=".$userid." and password=".$password; if($result = mysqli_query($db, $myQuery)) $num_results = mysqli_num_rows($result); // THIS LINE PRODUCES THE ERROR else ec...
by TJ
Fri Nov 04, 2005 7:27 am
Forum: PHP - Code
Topic: Redirect
Replies: 13
Views: 696

Response.Redirect("http://php.net") is the equivilent of header('Location: http://php.net'); PHP is just more faithful to HTTP - it lets you set the raw header rather than masking it. If you read up on the HTTP protocol (which all web-application developers should!) you'd see how useful he...
by TJ
Fri Nov 04, 2005 7:21 am
Forum: PHP - Code
Topic: how to traverse a string
Replies: 6
Views: 540

You could use a simple regular expression:

Code: Select all

$subject = "the quick BROWN FOX \t 012345 $ \r\nthis is the next line";
echo preg_replace('/[^\x20-\x7F]/','', $subject);
What this does is replace all characters that don't match the range 0x20 - 0x7F (32 - 127).
by TJ
Fri Nov 04, 2005 6:48 am
Forum: PHP - Code
Topic: Redirect
Replies: 13
Views: 696

Do you see those debugging echo statements? As far as PHP is concerned what they write is content and therefore headers are flushed. If you remove them the header() function calls will work as you expect. When debugging like this, its sometimes better to have a string variable that you add messages ...