wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
HUh! mod_rewrite works fine on my Windows dev box. The only tricky part is getting windows to create .htaccess files, you can't do it by right click > create new. I just go into notepad and save a blank file as ".htaccess" (including the quotes).
-
Detecting if a string has a certain character?
wildteen88 replied to rottenpixies's topic in PHP Coding Help
use a simple regex pattern to find spaces within a string: $name = 'rotten pixies'; if(preg_match('/[\s]/', $name)) { echo 'Your name contains spaces. This is an invalid character to be used'; } If you want to block other characters, such as underscores (_), pipes (|), astricks (*), etc... Then you can change the the pattern to this: '/[\s_|*]/' add as many characters as you like between the square brackets for characters you wish to disallowed. -
[SOLVED] I don't need Cialis or Viagra... how can I trim that out?
wildteen88 replied to simcoweb's topic in PHP Coding Help
comment out the header part for now. it is causing your script to not work correctly chane this: if(preg_match('/'.$keyword.'/i',$str)) { header("location: reject.htm");exit; //Or whatever the logout url is } else { to this: if(preg_match('/'.$keyword.'/i',$str)) { //header("location: reject.htm");exit; //Or whatever the logout url is } else { Now you can continue debugging your script. -
[SOLVED] I don't need Cialis or Viagra... how can I trim that out?
wildteen88 replied to simcoweb's topic in PHP Coding Help
mysql_real_escape is not a known (builtin) function and thus PHP kicks up the fatal error: to called to undefined function xxx in xyz on line 123 error message. I guess you mean to call mysql_real_escape_string function not mysql_real_escape (which doesn't exist) Also I would change your error checking to this: <?php foreach($_POST as $key => $value) { $POST[$field] = trim($value); } $err = ''; // input error checking if(isset($_POST['name']) || empty($_POST['name'])) { $err[] = 'Please enter your name.'; } if(isset($_POST['phone']) || empty($_POST['phone']) && !is_numeric($_POST['phone'])) { $err[] = 'Please enter a valid phone number. Phone numbers must only contain digits'; } // input error checking if(isset($_POST['email']) || empty($_POST['email'])) { $err[] = 'Please enter your email address.'; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $err[] = $email . ' is not a valid email address.'; } if(is_array($err)) { echo 'Please correct the following errors thank you:<br />'; echo '<ul><li>' . implode('</li><li>', $err) . '</li></ul>'; } else { // post our variables from the registration form $name = mysql_real_escape_string($_POST['name']); $phone = mysql_real_escape_string($_POST['phone']); $email = mysql_real_escape_string($_POST['email']); $facing_foreclosure = $name; $referred_by = mysql_real_escape_string($_POST['referred_by']); $comments = mysql_real_escape_string($comments); $today = date("F j, Y, g:i a"); // make database connection db_conn(); // mail the results to admin send_ebook_mail(); // run the query ebook_insert(); } } ?> Always validate raw $_POST data do not do $var = $_POST['var']; if($var=='') Revamped code: <?php // ebook registration and database insertion include 'db_config.inc'; if (isset($_POST['Submit'])) { // our attempt to stop spammers $keywords_list = file_get_contents('words.txt'); $banned_keywords = explode(',', $keywords_list); $comments = $_POST['comments']; foreach ($banned_keywords as $keyword) { if(preg_match('/' . trim($keyword) . '/i', $comments)) { header("location: reject.htm"); exit; } else { foreach($_POST as $key => $value) { $POST[$field] = trim($value); } $err = ''; // input error checking if(isset($_POST['name']) || empty($_POST['name'])) { $err[] = 'Please enter your name.'; } if(isset($_POST['phone']) || empty($_POST['phone']) && !is_numeric($_POST['phone'])) { $err[] = 'Please enter a valid phone number. Phone numbers must only contain digits'; } // input error checking if(isset($_POST['email']) || empty($_POST['email'])) { $err[] = 'Please enter your email address.'; } elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $err[] = $email . ' is not a valid email address.'; } if(is_array($err)) { echo 'Please correct the following errors thank you:<br />'; echo '<ul><li>' . implode('</li><li>', $err) . '</li></ul>'; } else { // post our variables from the registration form $name = mysql_real_escape_string($_POST['name']); $phone = mysql_real_escape_string($_POST['phone']); $email = mysql_real_escape_string($_POST['email']); $facing_foreclosure = $name; $referred_by = mysql_real_escape_string($_POST['referred_by']); $comments = mysql_real_escape_string($comments); $today = date("F j, Y, g:i a"); // make database connection db_conn(); // mail the results to admin send_ebook_mail(); // run the query ebook_insert(); } } } } ?> -
PHP command line with no server
wildteen88 replied to hobeau's topic in PHP Installation and Configuration
What happens you go to C:/php in the command prompt? to move the command prompt from the default C:/Documents and Settinsg/<username>/ directory when you start command promt type in the following command: cd C:/php/ and then press enter. The command prompt should now read C:/php> _ Now try running php through command prompt. -
Need help with finding a dynamic string in text
wildteen88 replied to igor berger's topic in PHP Coding Help
Just because your post is being ignored doesn't mean we are ignoring you/or being selfish as you put it. No one here gets paid for any help they do on this site. If you are getting help for free how can you complain? There could be many reasons why your questions don't get answered to, the most common one is posting unclear or complex questions. -
Set the path to just C:\wamp\php instead and not c:\wamp\php\php.exe. Make sure you restart Windows after changing/setting the path. Also make sure you have not set the path in 'User variables for xxx' box (replace xxx with your windows username). For some reason PHP does not read the variables set in that box. Make sure you set it in the 'System Variables' box instead.
-
Leave the cookie path out if you want to be able to access the cookie site wide. You don't need to set the cookie path to where you are setting it. That is not how cookie path works. cookie path works by limiting where the cookie can be accessed from.
-
aditt787 if you are new to PHP and MySQL then I highly recommend you to have read of the tutorials on this site. There you will learn the basics of both PHP and MySQL and how to use PHP with MySQL.
-
How to decode the <br /> tags I receive in my email?
wildteen88 replied to joseph's topic in PHP Coding Help
If you are sending html code in your email you will need to send the html header with your email. But looking at your code it looks like you need to change this line: $mail->IsHTML( false ); to this: $mail->IsHTML( true); -
[SOLVED] Getting an array from within a function..
wildteen88 replied to Dragen's topic in PHP Coding Help
You have not coded your function to return anything and thus you are getting nothing. Functions have there own scope so any variables you set in the function will not be abled to be accessed globaly unless you set them as global or return the variable. EDIT: I'd change your code to this: <?php //get variable arrays from database function get_variable_arrays($varname) { $sql = "SELECT * FROM variables WHERE `name` = '" . $varname . "' ORDER BY `value` ASC"; $result = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { $variable[$varname][$row['value']] = $row['value']; } return $variable; } else { return false; } } $arrayVar = get_variable_arrays('adspacea'); if(is_array($arrayVar)) { print_r($arrayVar); } else { echo 'No results returned'; } ?>[code] [/code] -
[SOLVED] Apache, PHP issue,
wildteen88 replied to Loran's topic in PHP Installation and Configuration
Save the file as index.php not .html. All PHP code must be in a file ending with a .php file extension. As for where to install PHP/Apache to I prefer not to install into C:/Program Files. I prefer to install AMP (Apache, MySQL and PHP) in the root of the hard drive placed in a folder called Server. I prefer to keep paths as short and as simple as possible. This is my directory listing when AMP is installed C:/Server | +-- Apache | +-- MySQL | +-- PHP | +-- www The www folder is where I place all my .php/html files to. I have configured Apache to serve C:/Server/www rather than the default htdocs folder. -
You'd be better of using urlencode if you are passing a string from a database through GET
-
Try a while loop $return = pg_query($pg_connection, $query); while ( $data = pg_fetch_array($return)) { echo print_ticket ($data['hash'], $data['name'], $data['ticket_no']); }
-
change the form method from post to get. However I think you can only upload via post
-
To convert to <b> you have to use regex. You can do a simple method using str_replace but it is inefficient and not very powerful compared to regex functions (preg_replace). To insert BBcode style tags into a textarea you don't need to use PHP. Instead you use javascript. There is most probably a javascript script already coded for you over at dynamicdrive.com or hotscripts.com. Just each google for BBCode or Javascript BBCode insertion.
-
Rather than echo'ing out the events when you find them. Save them to a variable which is an array call this variable, $events and then change this portion of code: if($month == $eventmonth){ //will only list month you specify in function. $out = "$day - $event<br>\n"; print $out; } To this: //will only list month you specify in function. if($month == $eventmonth) { // save each event for the month to the an array called events // we'll use the day as the key for the variable // the key will be used to sort the events in ascending order $events[$day] = $event; } Now after the foreach loop have this code: // order the keys in ascending order, remember the day is the key for the $events variable ksort($events); // display the events foreach($events as $day => $event) { echo "$day - $event<br />\n"; } Put it altogether an you get this: <?php function getevents($eventmonth) { $file = file("data.txt"); //puts each line of the file into an array //loop through array foreach($file as $key => $val) { $data[$key] = explode("|", $val); //breaks up each line into seperate arrays, values seperated by | $day = $data[$key][0]; $month = $data[$key][1]; $event = $data[$key][2]; //will only list month you specify in function. if($month == $eventmonth) { $events[$day] = $event; } } // order by day ksort($events); foreach($events as $day => $event) { echo "$day - $event<br />\n"; } } //Using the function getevents("Jan"); ?>
-
Rather than do a foreach loop outside of the function do it inside the function instead. Just pass your search terms as an array to your highlight_search_criteria function. SO your new code: <?php function highlight_search_criteria($search_results, $search_criteria, $bgcolor='Yellow') { $start_tag = "<span style='background-color: $bgcolor'>"; $end_tag = '</span>'; if(is_array($search_criteria)) { foreach($search_criteria as $term) { $highlighted_results = $start_tag . $term . $end_tag; $search_results = eregi_replace($term, $highlighted_results, $search_results); } } return $search_results; } $term[0] = 'John Doe'; $term[1] = 'Jane Smith'; $term[2] = 'Bill Bobbins'; $db_result_text = "The users with the most points in this game were John Doe, Jane Smith, and Bill Bobbins."; $result_text = highlight_search_criteria($db_result_text, $term); //result_text is the sentence or string with a highlighted word echo " result_text = ", $result_text; ?>
-
[SOLVED] Apache, PHP issue,
wildteen88 replied to Loran's topic in PHP Installation and Configuration
I guess you used the installer. When installing PHP it is best to not use the installer. Instead download the zipped binary package, Not the source code. Once you have downloaded the zip binary package just extract the zip to where you installed PHP to (I presume its C:/php and not C:/prgram files) and overwrite existing files. Once extracted open up your httpd.conf file which will be located in C:/Program Files/Apache Foundation/Apache2/conf. Note your path maybe different. Then just add the following lines to the httpd.conf: LoadModule php5_module "C:/php/php5apache2_2.dll" PHPIniDir "C:/php" AddType application/x-httpd-php .php Save the httpd.conf and restart Apache. It is important your restart Apache when you make any changes to Apache or PHP configuration. -
Could you post the exact version of PHP you are using. I cannot see why it wont work.
-
Use the following path: ./avatars/ and not /avatars If you are running it on a UNIX based platform, PHP will treate / as the root (of the hard drive) and so it will try to access a folder called avatars in the root of the hard drive. The root will be most probably out of bounds to you. What you want to do is place a period before the slash (./) this will tell PHP to look in the current directory and not the root.
-
How are you using it in your code. Post some of your code here. You may have applied in the wrong place/not using correctly.
-
Does your PHP setup have the short_open_tag directive enabled in the php.ini? As I se you use both <? and <?php tags. <? is used in the file that requires header.php What happens if you change this: <? $title = "My website title | page title" ?> <? $bodyID = 'b1'; ?> <?php require("header.php"); ?> to this: <?php $title = "My website title | page title" ?> <?php $bodyID = 'b1'; ?> <?php require("header.php"); ?> Does the error go away?
-
Does the code not work on your PHP setup? Even it has been coded for PHP3 it should still run on PHP4. There was no syntax change from 3 to 4. Just the PHP core (Zend Engine) has been improved to speed up processing and capabilities.
-
You don't need to use $sess_id = session_id();. Only if you want to use the session id in your script somewhere. session_write_close(); is only needed if you are using a frameset. This function can increase page load time if you are using a frame set, as explain by the manual: