PHP - Ereg & Eregi Php5
I'm sure this issue has been addressed before, but as I can't find anything on google OR bing, I've resorted to asking it he
Since, ereg and eregi are deprecated in PHP5, how do you test strings using regular expressions? Is there a new function for this? EDIT: I also looked on php.net, but all it says is its deprecated in PHP5. I didn't see any links to the new function(s) that have replaced the former. Similar TutorialsHelo, I need big help how to adjust this code to new PHP 5.3 that dont support egeri any more public static function blacklist(&$query) { return eregi(self::$_blacklist, $query) ? true : false; } HELP ! ! ! I have a small php upload/download script, it always worked on older php4 -5 but not on php5.3 ,gobal varitables must be on , I dont know to much about php and was hoping someone will look at at and let me know what to change to make it work on php5.3 or higher..............................THANKS! for any help in fixing this issue
<body link="#FFFF00" vlink="#FF0000" alink="#FFFF00"><? $extlimit = "yes"; //Do you want to limit the extensions of files uploaded $limitedext = array(".zip",".sim",".car",".jpg",".gif"); //Extensions you want files uploaded limited to. $sizelimit = "no"; //Do you want a size limit, yes or no? $sizebytes = "30033000"; //size limit in bytes $dl = "xxxxxxxxxxx"; //url where files are uploaded $absolute_path = "xxxxxxxxxxx"; //Absolute path to where files are uploaded $websiteurl = "xxxxxxxx"; //Url to you website $websitename = "Car File Manger"; if (!isset($action)) { $action = ""; } switch($action) { default: echo" <html> <head> <title>Upload Or Download</title> </head> <body> <a href=$PHP_SELF?action=upload>Upload</a> | <a href=$PHP_SELF?action=download>Download</a> | <a href=$websiteurl>Return to $websitename</a> <br><br> </body> </html>"; break; case "download": echo " <html> <head> <title>File Download</title> </head> <body><a href=$PHP_SELF?action=upload>Upload File</a> | <a href=$websiteurl>Return to $websitename</a>"; $list = "<table width=500 border=0 bordercolor=#000000 style=\"border-collapse: collapse\">"; $list .= "<tr><td width=500><center><b>Click To Download</b></center></td></tr>"; $dir = opendir($absolute_path); while($file = readdir($dir)) { if (($file != "..") and ($file != ".")) { //Download files with spaces fix by Kokesh $list .= "<tr><td width=700><a href='$dl/$file'>$file</a></center></td></tr>"; } } $list .= "</table>"; echo $list; echo" <br><br> </body> </html>"; break; case "upload": echo" <html> <head> <title>File Upload</title> </head> <body> <form method=POST action=$PHP_SELF?action=doupload enctype=multipart/form-data> <p>File to upload:<br> <input type=file name=file size=30> <p><button name=submit type=submit> Upload </button> </form> <br><br> </body> </html>"; break; //File Upload case "doupload": $dir = "dir"; if ($file != "") { if (file_exists("$absolute_path/$file_name")) { die("File already exists"); } if (($sizelimit == "yes") && ($file_size > $sizebytes)) { die("File is to big. It must be $sizebytes bytes or less."); } $ext = strrchr($file_name,'.'); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { die("The file you are uploading doesn't have the correct extension."); } @copy($file, "$absolute_path/$file_name") or die("The file you are trying to upload couldn't be copied to the server"); } else { die("Must select file to upload"); } echo " <html> <head> <title>File Uploaded</title> </head> <body>"; echo $file_name." was uploaded"; echo "<br> <a href=$PHP_SELF?action=upload>Upload </a> | <a href=$PHP_SELF?action=download> Download </a> | <a href=$websiteurl> Return to $websitename</a><br><br> </body> </html>"; break; } ?> Edited by Ch0cu3r, 01 September 2014 - 06:05 AM. It seems ereg is deprecated in php 5+ so what is a good alternative? Thanks! does anyone know why I am getting the error: Deprecated: Function ereg() is deprecated on line 75 ? here is line 75 (line 3, the seond if statement): if($form_cc_type == 'visa') { if(!ereg('^4[0-9]{12}([0-9]{3})?$', $form_cc_number)) { $form_error = "Invalid number"; } } I am assuming I would get a simular error on all the ereg lines... if($form_cc_type == 'visa') { if(!ereg('^4[0-9]{12}([0-9]{3})?$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'mastercard') { if(!ereg('^5[1-5][0-9]{14}$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'americanexpress') { if(!ereg('^3[47][0-9]{13}$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'diners') { if(!ereg('^3(0[0-5]|[68][0-9])[0-9]{11}$', $form_cc_number)) { $form_error = "Invalid number"; } } elseif($form_cc_type == 'discover') { if(!ereg('^6011[0-9]{12}$', $form_cc_number)) { $form_error = "Invalid number"; } } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320413.0 Hi: Is it possible to use the ereg() function in a file upload script so that the ereg() can recognize whether or not the file type is a .jpg, .gif, .png? I already figured out how to do it without using the ereg() function - but I'm just interested to know if it is possible using ereg()..if so, could you provide me with an example? I'm also a bit confused as to how to use ereg() to recognize file types. Here;s what I've done: Code: [Select] function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } Thanks! Hi, I currently have some PHP scripts that verify form data using ereg() as follows: if (ereg(".",$var1)==0) { //do something } where instead of the argument "." I also use "\@" or "\....*", etc. to test whether certain form input is in the correct format (e.g. testing for a valid email address, etc.). However, I have understood that ereg() is being deprecated. What is the best/easiest function to replace ereg() with? Thanks! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347016.0 IS it reliable to use eregi() to prevent email injection? if (eregi("(\r|\n)", $first) || eregi("(\r|\n)", $second)){ die("Spammer detected"); }else{ //do this }; I noticed eregi is deprecated, what would I use instead? Hello.I got some error in my code: Deprecated: Function eregi() is deprecated in config.php on line 84 This is my code if(!eregi( "^[a-zA-Z\-_0-9/-]+$", $type )) unset($type); if(!eregi( "^[a-zA-Z\-_0-9/]+$", $act )) unset($act); if(!eregi( "^[a-zA-Z\-_0-9/]+$", $id )) unset($id); Can someone help me what should be changed Code: [Select] if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ //email was valid } Trying to replace the eregi function with preg_match but i dont think its working. This is what i got: Code: [Select] if(preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ //this email is valid } What ever the content of $email in the preg_match version, it simply returns true... is the pattern wrong for preg_match? (patterns are no strong point of mine at the moment) here my code <html> <head><title>TESTING</title></head> <body> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"/> email: <input type=text name=email value="" /><br/> feedback: <input type=text name=ex value=""/><br/> <input type="submit" value="submit" /><br/> </body> </html> <?php $email = $_GET['email']; $ex = $_GET['ex']; if(!eregi('^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z]+$',$email)){ echo 'invalid email address<br/>'; } else { echo 'good to go<br/>'; } if(eregi('money|brooklyn|new york' ,$ex)){ echo '1'; } else { echo '0'; } ?> The code works fine but when i put on my error reporting i get that eregi is deprecated, now if eregi is depreciated which function should i use ? or should i just suppress the error ? I am having trouble trying to fix my eregi call in my script. I have a reporting tool that grabs information from the user agent when they email help questions. I used eregi to find the string in an array and print out when it finds a match. I don't fully understand the PCRE functions so i don' t know if i am using them right. what i have is foreach($OSList as $CurrOS=>$Match) { // Find a match if (eregi($Match, $_SERVER['HTTP_USER_AGENT'])) { // We found the correct match break; } } I know i need to change this around for PCRE preg_match maybe but i am not sure. if anyone could send me a tutorial or help me out it would be great. EDIT: notice the foreach was not correct Which is most efficient for finding a string within a string? Eregi or strpos? Currently im using Eregi to check a string again an array of blocked words and retrun true if one is present. But it seems i can do it also with strpos... so which is best function to use ? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346108.0 Hi Guys,
Firstly I would like state that I do not have a clue about PHP coding, I have merely signed up to gain some help with the following errors I have with my site I have recently setup with a PHP sports application.
I downloaded the application from the following website http://phpmysport.sourceforge.net/ and as far as I know the software is opensource and no longer supported by its developer.
The following http://www.proevoeliteleagues.esy.es/ is my website which displays the error messages.
Please see following code the files in question:
menu.php
<?php /* * phpMySport : website for team sport clubs and leagues * * Copyright (C) 2006-2009 Jerome PLACE. All rights reserved. * * Email : djayp [at] users.sourceforge.net * Website : http://phpmysport.sourceforge.net * Version : 1.4 * Last update : 4 march 2009 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ /****************************/ /* MENUS */ /****************************/ $file=ROOT."/menu.csv"; # file containing the website menu # list of default pages $default_pages=array( array('level'=>'parent','title'=>$lang['general']['home'],'url'=>'index.php','class'=>'menu_home'), array('level'=>'parent','title'=>$lang['general']['news'],'url'=>'index.php?r='.$lang['general']['idurl_news'].'&v1=news_list','class'=>''), array('level'=>'parent','title'=>$lang['general']['information'],'url'=>'index.php?r='.$lang['general']['idurl_information'],'class'=>''), array('level'=>'parent','title'=>$lang['general']['team_list'],'url'=>'index.php?r='.$lang['general']['idurl_team'].'&v1=team_list','class'=>''), array('level'=>'parent','title'=>$lang['general']['member_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=member_list','class'=>''), array('level'=>'child','title'=>$lang['general']['member_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=member_list','class'=>''), array('level'=>'child','title'=>$lang['general']['player_list'],'url'=>'index.php?r='.$lang['general']['idurl_team'].'&v1=player_list','class'=>''), array('level'=>'child','title'=>$lang['general']['manager_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=manager_list','class'=>''), array('level'=>'child','title'=>$lang['general']['coach_list'],'url'=>'index.php?r='.$lang['general']['idurl_team'].'&v1=coach_list','class'=>''), array('level'=>'child','title'=>$lang['general']['referee_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=referee_list','class'=>''), array('level'=>'parent','title'=>$lang['general']['match_list'],'url'=>'index.php?r='.$lang['general']['idurl_match'],'class'=>''), array('level'=>'child','title'=>$lang['general']['match_list'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=match_list','class'=>''), array('level'=>'child','title'=>$lang['general']['standings'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=standings','class'=>''), array('level'=>'child','title'=>$lang['general']['stats_player'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=stats_player','class'=>''), array('level'=>'parent','title'=>$lang['general']['competition_list'],'url'=>'index.php?r='.$lang['general']['idurl_competition'].'&v1=competition_list','class'=>''), //array('order'=>'6.1','title'=>$lang['general']['statistics'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=statistics','class'=>''), //array('order'=>'8.0','title'=>$lang['general']['search_member'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=search_member','class'=>''), array('level'=>'parent','title'=>$lang['general']['club_list'],'url'=>'index.php?r='.$lang['general']['idurl_club'],'class'=>''), array('level'=>'parent','title'=>$lang['general']['field_list'],'url'=>'index.php?r='.$lang['general']['idurl_field'],'class'=>''), array('level'=>'parent','title'=>$lang['general']['forum_list'],'url'=>'index.php?r='.$lang['general']['idurl_forum'],'class'=>'') ); $website_menu=array(); # we load the menu if(file_exists($file) AND $fp=fopen($file, "r") AND filesize($file)!=0) { $i=0; while (($data = fgetcsv($fp, 1000, ";")) !== FALSE) { $website_menu[$i]['level']=$data[0]; $website_menu[$i]['title']=$data[1]; $website_menu[$i]['url']=$data[2]; $website_menu[$i]['class']=$data[3]; $website_menu[$i]['target']=$data[4]; $i++; } fclose($fp); } else { $website_menu=$default_pages; } $k=0; $i=-1; foreach($website_menu AS $value) { if(!isset($value['target'])) $value['target']=''; if(!eregi("http",$value['url'])) { $value['url']=convert_url($value['url']); } if($value['level']=='parent') { $i++; $j=0; $index['menu'][$i]=$value; $index['menu'][$i]['i']=$k; $index['menu'][$i]['submenu']=array(); } else { $index['menu'][$i]['submenu'][$j]=$value; $index['menu'][$i]['submenu'][$j]['i']=$k; $j++; } $k++; } /* # team of the club $index['team']=array(); if(CLUB!=0) { if(!isset($_SESSION['menu_team'])) { $var['condition']=""; $var['limit']=""; $var['order']=" ORDER BY e.sex_id, ne.team_name_name ASC"; $included=1; include_once(create_path("team/sql_team.php")); include_once(create_path("team/tpl_team.php")); include_once(create_path("team/lg_team_".LANG.".php")); include(create_path("team/team_list.php")); unset($included); $_SESSION['menu_team']=$page['team']; } $index['team']=$_SESSION['menu_team']; } # information pages list $index['information']=array(); if(!isset($_SESSION['menu_information'])) { $var['condition']=""; $var['limit']=""; $var['order']=""; $included=1; include_once(create_path("information/sql_information.php")); include_once(create_path("information/tpl_information.php")); include_once(create_path("information/lg_information_".LANG.".php")); include(create_path("information/page_list.php")); unset($included); $_SESSION['menu_information']=$page['page']; } $index['information']=$_SESSION['menu_information']; # forums list $index['forum']=array(); if(!isset($_SESSION['menu_forum'])) { $var['condition']=""; $var['limit']=""; $var['order']=""; $included=1; include_once(create_path("forum/sql_forum.php")); include_once(create_path("forum/tpl_forum.php")); include_once(create_path("forum/lg_forum_".LANG.".php")); include(create_path("forum/forum_list.php")); unset($included); $_SESSION['menu_forum']=$page['forum']; } $index['forum']=$_SESSION['menu_forum']; # competition list $index['competition']=array(); if(!isset($_SESSION['menu_competition'])) { $var['condition']=""; $var['limit']=""; $var['order']=""; $included=1; include_once(create_path("competition/sql_competition.php")); include_once(create_path("competition/tpl_competition.php")); include_once(create_path("competition/lg_competition_".LANG.".php")); include(create_path("competition/competition_list.php")); unset($included); $_SESSION['menu_competition']=$page['competition']; } $index['competition']=$_SESSION['menu_competition']; # plugins $index['plugin']=array(); $nb_plugin=sizeof($plugin); $j=0; for($i=0; $i< $nb_plugin; $i++) { if($plugin[$i]['active']==1) { $index['plugin'][$j]['name']=$plugin[$i]['name']; $index['plugin'][$j]['link']=$plugin[$i]['link']; $index['plugin'][$j]['class']=$plugin[$i]['class']; $j++; } } #text $index['L_home']=$lang['general']['home']; $index['L_news']=$lang['general']['news']; $index['L_information']=$lang['general']['information']; $index['L_member']=$lang['general']['member']; $index['L_member_list']=$lang['general']['member_list']; $index['L_player_list']=$lang['general']['player_list']; $index['L_manager_list']=$lang['general']['manager_list']; $index['L_coach_list']=$lang['general']['coach_list']; $index['L_referee_list']=$lang['general']['referee_list']; $index['L_match']=$lang['general']['match']; $index['L_match_list']=$lang['general']['match_list']; $index['L_standings']=$lang['general']['standings']; $index['L_stats_player']=$lang['general']['stats_player']; $index['L_competition_list']=$lang['general']['competition_list']; $index['L_team_list']=$lang['general']['team_list']; $index['L_statistics']=$lang['general']['statistics']; $index['L_search_member']=$lang['general']['search_member']; $index['L_club_list']=$lang['general']['club_list']; $index['L_view_club']=$lang['general']['view_club']; $index['L_field_list']=$lang['general']['field_list']; $index['L_forum_list']=$lang['general']['forum_list']; */ # mode club $index['link_view_club']=""; $index['class_view_club']=""; if(CLUB!=0){ $index['link_view_club']=convert_url("index.php?r=".$lang['general']['idurl_club']."&v1=view&v2=".CLUB); $index['L_club_list']=$lang['general']['club_opponent_list']; $index['L_information']=$lang['general']['the_club']; if(isset($_GET['r']) AND $_GET['r']==$lang['general']['idurl_club'] AND isset($_GET['v2']) AND $_GET['v2']==CLUB) { $index['class_information']="on"; $index['class_club']=""; } } ?>fonctions.php Im new to php and Im working on a script that I purchased. I'm getting this error when I try to setup my script. I did some research and understand that I "eregi" is old code and not being used anymore. So I tried to use preg_match but I'm stuck. If anyone can look at the code and help with some notes. I would like to understand what im doing wrong not just a fix. Deprecated: Function eregi() Code: [Select] if (eregi($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; This is what I get when using preg_match. preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash Code: [Select] if (preg_match($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315924.0 I need to produce 4 byte CRC32 checksums for UDP packets sent to an rcon tool for an online game. The (brief) specification for formatting these UDP packets is he http://www.battleye.com/downloads/BERConProtocol.txt I have been converting the results of the CRC32() to hex and inserting it successfully in the correct part of the packet. The checksum result however is different from one that I packet captured from a working rcon tool. I have tried various methods of converting the int that CRC32 produces but have been unsuccessful in producing the correct checksum. For reference below is the captured correct packet from the working tool. All data is the same as the packets my tool produces except for the checksum. The checksum is bytes 3,4,5 & 6. and is formed (to my understanding) by performing a CRC32 check on the subsequent bytes. (From Smartsniff) 00000000 42 45 D5 C3 FB ED FF 00 61 62 63 64 65 31 32 BE...... abcde12 If anyone has a working CRC32 class that could reproduce the successful hash above or has any pointers in the correct direction I would be very thankful. |