CoderZone.org
  Show Posts
Pages: 1 2
1  General Category / General Discussion & Chit Chat / Re: Looking for a nice "1940's" style theme on: Apr 13, 2011, 11:17:03 am
Is it for an existing, open source application or are you building a custom system?
2  Server Scripting / PHP / Re: mysql_real_unescape_string ? on: Apr 08, 2011, 06:29:47 am
I found the root cause of the problem.

The data is inserted into the database through Perl scripts, which my code calls.  I had an extraneous addslashes call in with the escapeshellargs (duh), which was causing the backslashes to be added in to the database.

All the 'unescape' code was workarounds and I removed it.

I'm pretty ashamed of myself.

This is the SQL I used to clean up the database.

Code:  
Highlight Mode: (MySQL)
  1. UPDATE `service_provider` SET `name`=REPLACE(`name`,"\\",""),`contact_information`=REPLACE(`contact_information`,"\\","");
 

Thanks for the ideas, they really helped.
3  Server Scripting / PHP / Re: mysql_real_unescape_string ? on: Apr 07, 2011, 02:15:46 pm
Thanks for the ideas ...

Ran phpinfo() through the web

Quote
magic_quotes_gpc   Off   Off
magic_quotes_runtime   Off   Off
magic_quotes_sybase   Off   Off
       

Then I checked the code to see exactly what I have.  Right now there are at least two approaches I'm using, until I find a better solution:

Code:  
Highlight Mode: (PHP)
  1. $sQuery = 'SELECT `name`,`service_provider_id` AS \'id\' FROM `service_provider` ';
  2.        $sQuery.=' ORDER BY `name`';
  3.        $this->db->query($sQuery);
  4.        $aResult=array();
  5.        while ($rResult = $this->db->fetch_assoc())
  6.                $aResult[]=str_replace('\\','',$rResult);
  7.        $this->db->free_result();
  8.        return $aResult;
  9.  
 

Code:  
Highlight Mode: (PHP)
  1.        $sCols.='`route`.`name` AS \'name\',REPLACE(`service_provider`.`name`,\'\\\\\',\'\') AS  \'service_provider_name\','';
  2.  
 

As you can see - the backslashes are in the database ...

Code:  
Highlight Mode: (MySQL)
  1. mysql> select service_provider_id,name from service_provider;
  2. +---------------------+------------------------------+
  3. | service_provider_id | name                         |
  4. +---------------------+------------------------------+
  5. |                   3 | Amy\'s SP                   |
  6. |                   1 | default                      |
  7. +---------------------+------------------------------+
  8. 2 rows in set (0.00 sec)
 
 
I'm stumped, and I'm pretty sure there is a simple solution that I just can't find.
4  Server Scripting / PHP / mysql_real_unescape_string ? on: Apr 02, 2011, 01:09:38 pm
I have some strings that I used mysql_real_escape_string on prior to putting them in the database and now ... needless to say ... they're coming out with backslashes  ...

I resorted to the following:

SELECT REPLACE ( `field`,"\","" ) AS `field` FROM `table`;

am I missing a better solution?
5  General Category / General Discussion & Chit Chat / Re: IT World: Apple to buy Redhat? on: Apr 01, 2011, 07:55:14 am
Additional information
6  Security & Performance / Security Issues / Re: Sanitizing email form on: Mar 30, 2011, 10:55:16 am
If I can get away with it, I like to use a positive filter - meaning allow only 'friendly' or 'safe' characters through for text fields.

One possible regex is
Code:  
Highlight Mode: (PHP)
  1. preg_match('/^\w\,\.\ $/',$sData)
 
.  If it isn't a letter or number, comma, space or period, it is refused.

It may sound harsh or restrictive, but after an initial contact, you have a bit of a trusted relationship and can just use regular email to communicate.
7  Browser Scripting / CSS / Re: Pure CSS GUI Icons on: Mar 29, 2011, 09:45:35 am
Awesome!  Thanks!
8  Browser Scripting / CSS / Re: CSS from PHP - why doesn't it work? on: Mar 26, 2011, 07:47:01 pm
It took awhile.   Smiley
9  General Category / General Discussion & Chit Chat / Re: Carnegie Mellon University dumps object-oriented programming on: Mar 26, 2011, 07:45:03 pm
Wow!

I had my first OO class many years ago.  I didn't really grasp it until now, and I'm still learning.  It's definitely a different mindset.

I don't think it should be used everywhere, but I really like using it within a web MVC architecture as the model, representing the data - however - I've learned to be careful with it, to avoid unnecessary overhead instantiating classes. 

I agree that it isn't first year content, but it can be valuable.

I think the advantages are that you can represent data nicely, you can encapsulate the data, and extend and override classes and operators.  Those things can be difficult to do with a procedural language. 

I like the comments on the blog post, too.
10  Server Scripting / PHP / Re: Using mail() on certain hosts on: Mar 26, 2011, 10:54:48 am
This might be worth a try as well, you could set it with .htaccess at the account level.

http://www.php.net/manual/en/mail.configuration.php#ini.sendmail-from
11  Browser Scripting / CSS / Re: CSS from PHP - why doesn't it work? on: Mar 26, 2011, 07:02:45 am
I found the answer by comparing the headers sent by .js and .css files that didn't run through PHP using FireBug.  I needed to set a the Content-Type header, because the rewrite was causing the Content-Type to be set as "Content-Type   text/html; charset=UTF-8"

Code:  
Highlight Mode: (PHP)
  1. <?php require_once 'common.php'; ?>
  2. <?php header('Content-Type:text/css; charset=utf-8;') ?>
 

Worked - for the CSS, and I put it in the js, too.
12  Browser Scripting / CSS / Re: CSS from PHP - why doesn't it work? on: Mar 24, 2011, 05:42:02 pm
I'm using dojo to load it, and the CSS depends on an id, which is what PHP is adding.

These are the lines in the XHTML document:

Code:  
Highlight Mode: (HTML)
  1. <link type="text/css" src="" rel="stylesheet" id="lnkCapuchin" />
  2. <script type="text/javascript" src="http://o.aolcdn.com/dojo/1.5/dojo/dojo.xd.js">var djConfig={parseOnLoad:true};</script>
  3. <script type="text/javascript" src="<?php echo $iId ?>-capuchin.js" id="srcCapuchin"></script>
 

The <link> tag is just a marker, when distributed, people will receive a key, they will add instead of the echo $iId, and I wanted the code to run where they just paste the above three lines in an XHTML document and a few tags in a form later.

In the script file, which is javascript processed through PHP, the href is set.

Code:  
Highlight Mode: (Javascript)
  1. dojo.addOnLoad(function()
  2. {
  3. dojo.byId('lnkCapuchin').href='<?php echo $iId ?>-capuchin.css';
 

These are the rewrite rules - the id is stripped off and passed on the query string.

Code:  
RewriteRule ^([\d]+)-capuchin.js$ capuchin.js.php?$1 [L]
RewriteRule ^([\d]+)-capuchin.css$ capuchin.css.php?$1 [L]

I saw a post here about running all .js requests through PHP - but I really only want these two requests rewritten.

Maybe the best answer would be to just put the id in the <link> tag?
13  Browser Scripting / CSS / Re: CSS from PHP - why doesn't it work? on: Mar 23, 2011, 03:12:37 pm
common.php just has session initialization stuff.

Code:  
Highlight Mode: (PHP)
  1. <?php require_once 'common.php'; ?>
  2. @import "http://o.aolcdn.com/dojo/1.4/dojo/resources/dojo.css";
  3. @import "http://o.aolcdn.com/dojo/1.4/dojo/resources/dnd.css";
  4. @import "http://o.aolcdn.com/dojo/1.4/dijit/themes/tundra.css";
  5. body
  6. {
  7. background-color:pink;
  8. }
  9. div#divCapuchin div#divSourceContainer,div#divCapuchin div#divTargetContainer
  10. {
  11. width:300px;
  12. height:200px;
  13. }
  14. div#divCapuchin div.segment
  15. {
  16. width:48px;
  17. height:181px;
  18. float:left;
  19. margin:1px;
  20. overflow:hidden;
  21. }
  22. <?php for ($i=0;$i<SEGMENTS;$i++): ?>
  23. div#divCapuchin div#divTargetContainer div#divTarget-<?php echo $i ?>
  24. {
  25. float:left;
  26. background:transparent url(images/cats-light.jpg) no-repeat -<?php echo (SEGMENT_WIDTH*$i)+1 ?>px 0px;
  27. }
  28. <?php endfor ?>
  29. .break
  30. {
  31. float:none;
  32. clear:both;
  33. }
  34.  
 

14  Browser Scripting / CSS / CSS from PHP - why doesn't it work? on: Mar 23, 2011, 10:11:49 am
I'm using PHP to compose some CSS.  It's created correctly, and delivered to the browser, but it isn't taking effect.

What's wrong?

 Huh
15  Security & Performance / Security Issues / Quick look at visitors from the Apache log on: Mar 16, 2011, 07:31:20 am
This is CentOS5

Code:  
Highlight Mode: (Bash)
  1. cut -f1 -d' ' /etc/httpd/logs/access_log | sort | uniq | xargs -L1 host
 

What it is doing ...

This is a sample row from a default Apache access_log

1.2.3.4 - - [14/Mar/2011:12:19:18 -0400] "GET /index.php/rss/feed/main HTTP/1.1" 404 7210 "-" "Windows-RSS-Platform/2.0 (MSIE 8.0; Windows NT 6.1)"

The cut command cuts the IP address out, using a space for a delimiter.

The sort command sorts all the IP addresses, and uniq removes all the duplicates.

Finally, the information is fed into xargs which executes host to get the domain name.
16  General Category / General Discussion & Chit Chat / Re: SIte conversion from tables to CSS/divs on: Mar 15, 2011, 05:57:27 am
Quote
I have access to the content directly, so I was considering several intermediate steps.

Does this mean the content is in a database or that you have a collection of static HTML files?

It all depends on the structure of the pages.  Is it fairly constant?  Can you post a representative sample?

If h tags were used properly, and the pages are fairly close to valid XHTML, stripping out all the font tags and inline style attributes may be enough.

Also - cleaning the code up in phases, may be worth considering - so at the end of the first phase you have clean pages with tables, and then you can return later and add more style, and finally, transition to divs if you have time.
17  General Category / General Discussion & Chit Chat / Re: SIte conversion from tables to CSS/divs on: Mar 14, 2011, 07:23:04 am
I'd skip it.

Most people look at the page, read the information and move on.

As long as the pages display correctly - you might as well leave them.

When I Google for an answer, I never check how the page is coded - I read/copy what I need and then leave.

18  Server Scripting / PHP / Re: PHP Warning: Illegal offset type in isset or empty on: Mar 08, 2011, 06:31:21 am
try using the string parsing ...

http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing
19  Server Scripting / PHP / Re: Auto-link text, but not if already inside a link...? on: Feb 13, 2011, 05:48:17 pm
Minor updates - added the limit paramater on the preg_replace to ensure only the first instance is replaced.  Removed the test for links, which was unnecessary.

Code:  
Highlight Mode: (PHP)
  1. <?php
  2. $string='The dog is a domesticated form of the gray wolf, a member of
  3. the Canidae family of the order Carnivora. The term <a href="http://doggie.com">"dog"</a> is used for
  4. both feral and <a href="http://pet.com">pet</a> varieties. The domestic dog has been the most
  5. widely kept working, hunting and companion animal in human history.';
  6.  
  7. echo 'Original string'.PHP_EOL.$string.PHP_EOL;
  8.  
  9. // Remove all but the link tags
  10. $stripped=strip_tags($string,'<a>');
  11.  
  12. // Extract all the links
  13. $matches=array();
  14. $links=preg_match_all('#<a[^>]+>([^<]*)</a>#s',$stripped,$matches);
  15.  
  16. // Array with links for new terms
  17. $link_array=array('dog'=>'http://puppy.com','"dog"'=>'http://doggie2.com','cat'=>'http://kitty.com','pet'=>'http://pet.com','companion'=>'http://buddy.com');
  18.  
  19. // Go through all the links.  Restore those removed, or replace the new text
  20. foreach ($link_array as $k => $v)
  21. {
  22.        if (($i=array_search($k,$matches[1]))!==false)
  23.                $link=preg_replace('/<a href=[\'\"]([^>^\'^\"]*)[\'\"]*[^>]+>(.*)$/','$1',$matches[0][$i]);
  24.        else
  25.                $link=$v;
  26.        $patterns[]='/\W+'.preg_quote($k).'\W+/';
  27.        $replacements[]=' <a href="'.$link.'">'.$k.'</a> ';
  28. }
  29. // Remove all tags
  30. $stripped=strip_tags($string);
  31.  
  32. $new=preg_replace($patterns,$replacements,$stripped,1);
  33. echo 'Updated string'.PHP_EOL.$new.PHP_EOL;
 


Original string
Code:  
Highlight Mode: (HTML)
  1. The dog is a domesticated form of the gray wolf, a member of
  2. the Canidae family of the order Carnivora. The term <a href="http://doggie.com">"dog"</a> is used for
  3. both feral and <a href="http://pet.com">pet</a> varieties. The domestic dog has been the most
  4. widely kept working, hunting and companion animal in human history.
 
Updated string
Code:  
Highlight Mode: (HTML)
  1. The <a href="http://puppy.com">dog</a> is a domesticated form of the gray wolf, a member of
  2. the Canidae family of the order Carnivora. The term <a href="http://doggie.com">"dog"</a> is used for
  3. both feral and <a href="http://pet.com">pet</a> varieties. The domestic dog has been the most
  4. widely kept working, hunting and <a href="http://buddy.com">companion</a> animal in human history.
  5.  
 
20  Server Scripting / PHP / Re: Auto-link text, but not if already inside a link...? on: Feb 13, 2011, 08:46:11 am
The first dog didn't get auto-linked, because the list has quotes, and the word didn't.  The "dog" did not get updated because it already had a link. 

I didn't test this as carefully as I could have, concerns/issues/notes:

It might not keep track of whether it placed a link or not, but preg_replace may only replace the first instance by default, which would comply.

All the other tags are removed, which may be a good thing - or not.

It didn't replace the 'cat' in domesticated - which is good, because of the 'non-word' delimiters.

Pages: 1 2