Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.30.01 RN New Installation Issues
Author Message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Thu Jan 21, 2010 7:41 am Reply with quote

I was referring to the "i" that you added to the end of the search pattern.

So, if you wanted to use preg_match and look for that exact match (ALL CAPS) rather than also finding "MsiE" for example), remove the 'i' like this:

Code:


if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {


I am just letting you know that what you wrote is NOT 100% the same as the ereg is all.

In addition, this would be faster, but less flexible:

Code:


if (strpos('MSIE', $_SERVER['HTTP_USER_AGENT'])) {

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
jalaklenteng
New Member
New Member



Joined: Feb 18, 2010
Posts: 1

PostPosted: Thu Feb 18, 2010 8:11 pm Reply with quote

Palbin wrote:
Look in rnconfig.php for $error_reporting = E_ALL^E_NOTICE; (around line 82) and change it to this $error_reporting = E_ALL^E_NOTICE^E_DEPRECATED;


where i can find the rnconfig.php?
 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Thu Feb 18, 2010 9:04 pm Reply with quote

It should be in the root directory of your site. Where config.php resides.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1123

PostPosted: Tue Apr 13, 2010 1:33 am Reply with quote

Thanks for your explanation montengo. Let's see if I got the point

Example
Code:
if (ereg('IIS', $_SERVER['SERVER_SOFTWARE']) && isset($_SERVER['SCRIPT_NAME'])) {


Replace with
Code:
if (preg_match('/IIS/', $_SERVER['SERVER_SOFTWARE']) && isset($_SERVER['SCRIPT_NAME'])) {


Is this correct?

I would like to correct this group of lines. Can you give me an example?

Code:
function check_words($Message) {

   global $CensorMode, $CensorReplace, $EditedMessage, $CensorList;
   include_once(INCLUDE_PATH.'config.php');
   $EditedMessage = $Message;
   if ($CensorMode != 0) {
      if (is_array($CensorList)) {
         $Replace = $CensorReplace;
         if ($CensorMode == 1) {
            for ($i = 0; $i < count($CensorList); $i++) {
               $EditedMessage = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$Replace\\1",$EditedMessage);
            }
         } elseif ($CensorMode == 2) {
            for ($i = 0; $i < count($CensorList); $i++) {
               $EditedMessage = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$Replace",$EditedMessage);
            }
         } elseif ($CensorMode == 3) {
            for ($i = 0; $i < count($CensorList); $i++) {
               $EditedMessage = eregi_replace("$CensorList[$i]","$Replace",$EditedMessage);
            }
         }
      }
   }
   return $EditedMessage;
}
 
View user's profile Send private message
montego







PostPosted: Sat Apr 17, 2010 4:50 pm Reply with quote

unicornio, try something like this:

Code:


$EditedMessage = preg_replace("/$CensorList[$i]([^a-zA-Z0-9])/i","$Replace\\1",$EditedMessage);


See if that works.
 
hicuxunicorniobestbuildpc







PostPosted: Sat Apr 24, 2010 9:15 am Reply with quote

montego,

Thanks, I understood already what was the differents between sensitive and insensitive.

What you wrote above is really important for me now.

Quote:
In addition, this would be faster, but less flexible:

if (strpos('MSIE', $_SERVER['HTTP_USER_AGENT'])) {



Are you telling me pre_match is not faster than strpos. Can you please explain to me when you need to use it and why it is more fast.

Question Question Question Question
 
jakec
Site Admin



Joined: Feb 06, 2006
Posts: 3048
Location: United Kingdom

PostPosted: Sat Apr 24, 2010 10:11 am Reply with quote

unicornio wrote:

Are you telling me pre_match is not faster than strpos. Can you please explain to me when you need to use it and why it is more fast.


If you search the internet you will find many articles benchmarking strpos against preg_match.
 
View user's profile Send private message
hicuxunicorniobestbuildpc







PostPosted: Sun May 02, 2010 4:31 am Reply with quote

Hi everybody

I am getting an error when I want to conver this line


Code:
         elseif (eregi("http://", $user_avatar)) {


it became this

Code:
         elseif (preg_match("/http:///i", $user_avatar)) {


but I get one error from here

http:///

Should I do it like this

Code:
         elseif (preg_match("/http://\/i", $user_avatar)) {


I did it but I still get the error.
 
Palbin







PostPosted: Sun May 02, 2010 9:10 am Reply with quote

elseif (preg_match("/http:\/\//i", $user_avatar)) {
 
hicuxunicorniobestbuildpc







PostPosted: Mon May 10, 2010 3:20 pm Reply with quote

Very Happy

Palbin, thanks. I understand now more about this issue. Everytime I find any different. lol. I guess I can convert them almost all but I was working right now on this one but I get access denied.

Code:
if ( !eregi( "mainfunctions.php", $PHP_SELF ) ) {


   die( "You can't access this file directly ..." );

}


I replaced with this one


Code:
if ( !preg_match( "/mainfunctions.php/i", $PHP_SELF ) ) {


   die( "You can't access this file directly ..." );

}


but unfortunatly I get You can't access this file directly when I go the module. I do know my server is running php as a CGI but I dont want to paste that code into the mainfile.php. What should do? I read all Access Denied here Very Happy but I didnt find anything like this.

Shocked Let me know please.
 
Palbin







PostPosted: Mon May 10, 2010 3:37 pm Reply with quote

If that is for a modules switch it over to use the constant.

if (!defined('MODULE_FILE')) {
die ("You can't access this file directly...");
}
 
slackervaara
Worker
Worker



Joined: Aug 26, 2007
Posts: 236

PostPosted: Mon Jun 14, 2010 12:54 am Reply with quote

Which program do you recommend to make such substitions in multiple files in Linux?
I have been thinking about regexxer.
 
View user's profile Send private message
hicuxunicorniobestbuildpc







PostPosted: Wed Jun 16, 2010 2:40 pm Reply with quote

Is there any tool for windows?
 
slackervaara







PostPosted: Thu Jun 17, 2010 12:40 am Reply with quote

Maybe Replace Text might work and it is freeware.
http://www.ecobyte.com/replacetext/
 
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Thu Jun 17, 2010 11:57 pm Reply with quote

For linux, I recommend you become familiar with the command: sed


As for the php version of all this, I was wondering if anyone considered having apd installed?

I'm thinking it might be a bit much for the average user, or might be too much of a requirement, but if you happen to be able to install apd into your php install, you could make an include at the top of mainfile.php to override functions.php(example only).

Here's an example of the code I'd use for the eregi function:

Code:


override_function('eregi','$needle,$haystack','return rn_eregi($needle,$haystack);');

function rn_eregi($needle, $haystack){
return (preg_match("/".$needle."/i", $haystack));
}


rename_function("__overridden__", 'something_random');

override_function('ereg','$needle,$haystack','return rn_ereg($needle,$haystack);');

function rn_ereg($needle, $haystack){
return (preg_match("/".$needle."/", $haystack));
}

rename_function("__overridden__", 'something_else_random');



After you override a function, you have to undeclare the __overridden__ function, which I do by renaming it.

_________________
For those who stand shall NEVER fall and those who fall shall RISE once more!! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
hicuxunicorniobestbuildpc







PostPosted: Fri Nov 05, 2010 7:19 pm Reply with quote

Depracated

Code:
if( !eregi( $MSAph, $msaurl ) )  {



Is this correct

Code:
if( !stripos( $MSAph, $msaurl ) )  {


Help to convert this line if it is wrong. Thanks in advance,
 
PHrEEkie
Subject Matter Expert



Joined: Feb 23, 2004
Posts: 358

PostPosted: Fri Nov 05, 2010 11:06 pm Reply with quote

unicornio wrote:
Depracated

Code:
if( !eregi( $MSAph, $msaurl ) )  {



Is this correct

Code:
if( !stripos( $MSAph, $msaurl ) )  {


Help to convert this line if it is wrong. Thanks in advance,


As a coding preference, whenever I see/use a variable as the haystack, I always clearly separate it from the code for debugging purposes. Also, a variable MIGHT have characters in it from user input, which might crash a PCRE Regex. It's best to use preg_quote on the variable. It would all look like this:

Code:
SOLUTION CODE A:

if(!preg_match('/' . preg_quote($MSAph) . '/i',$msaurl)) {


If you are absolutely 100% positively sure that the variable is safe, then:

Code:
SOLUTION CODE B:

if(!preg_match('/' . $MSAph . '/i',$msaurl)){


Notice I am using single quotes to create strings for the delimiters. That is because I am separating the variable off by itself. If you want to write the most compact code, and again, this is a style/readability issue for other programmers who might wander into this line of code, you must use double quotes. Double quotes expand the variable, single quotes makes it literal.

Here are two compact examples, and how PHP would interpret them. Let's say $MSAph currently holds the value of SOMEDATA.

Code:
Double quoted:

if(!preg_match("/$MSAph/i",$msaurl)){

would be interpreted as:
if(!preg_match("/SOMEDATA/i",$msaurl)){


while
Code:
Single quotes:

if(!preg_match('/$MSAph/i,$msaurl)){

would be interpreted literally:
if(!preg_match('/$MSAph/i',$msaurl)){


In the last example, since the variable wasn't expanded, the REGEX is looking for the text msaph (the /i after the last delimiter makes the search case-insensitive, so the casing is made moot), and also it is looking for it at the FRONT of a string (the $). Clearly not what we want to accomplish. Although that example likely would NOT crash the script or produce any warning, it also isn't what we want. Understanding single and double quoted strings is essential to writing good code. Good luck!

- Keith

_________________
PHP - Breaking your legacy scripts one build at a time. 
View user's profile Send private message
hicuxunicorniobestbuildpc







PostPosted: Sat Nov 06, 2010 7:59 am Reply with quote

Create a new post for any other deprecated or warning

http://www.ravenphpscripts.com/postp151799.html#151799


Last edited by hicuxunicorniobestbuildpc on Sat Nov 06, 2010 6:07 pm; edited 1 time in total 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Sat Nov 06, 2010 4:33 pm Reply with quote

unicornio to avoid confusing other readers, would you mind posting these in the PHP forum in the future, if the code is not specific to RN?
I am concerned people will come across this and then running off to apply these code changes to RN when it is not used within RN.
 
View user's profile Send private message Send e-mail
hicuxunicorniobestbuildpc







PostPosted: Sat Nov 06, 2010 6:09 pm Reply with quote

it is already done. Thanks for warning me. I edited my last post.
 
djmaze
Subject Matter Expert



Joined: May 15, 2004
Posts: 727
Location: http://tinyurl.com/5z8dmv

PostPosted: Sun Nov 07, 2010 12:07 pm Reply with quote

Palbin wrote:
Look in rnconfig.php for $error_reporting = E_ALL^E_NOTICE; (around line 82) and change it to this $error_reporting = E_ALL^E_NOTICE^E_DEPRECATED;
mantasledge wrote:
Thanks Pablin! That fixed it Wink


It doesn't fix it, it only hides the issue Razz

_________________
$ mount /dev/spoon /eat/fun auto,overclock 0 1
ERROR: there is no spoon
http://claimedavatar.net/ 
View user's profile Send private message Visit poster's website
Palbin







PostPosted: Sun Nov 07, 2010 9:41 pm Reply with quote

I would have to question if it is actually an issue in the first place Wink
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.30.01 RN New Installation Issues

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©