Jump to content

stlewis

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

About stlewis

  • Birthday 07/21/1982

Contact Methods

  • Website URL
    http://www.thoughtsandrambles.com

Profile Information

  • Gender
    Male
  • Location
    California, United States

stlewis's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have an interesting situation that may not actually have anything to do with PHP, but I want to eliminate all possibilities. I'm developing a website using a home-rolled MVC framework. I'm using mod_rewrite in an .htaccess file located in my root directory so that all requests are routed to a controller that calls file_get_contents to pull a template and render that on the page. The problem I'm having is that I seem to be rendering a cached version of the template, no matter how many times I refresh or reset my browser cache...What I'm trying to determine is which may be the culprit...something to do with caching in PHP, or something to do with mod_rewrite, or something I'm just not thinking of? Any help would be appreciated! Steve
  2. Hi all! I have a little bit of a problem including class files... I have a php page, (say index.php) wherein I am requiring two other files, (class1.php, class2.php). Each of these files contain a definition for one class. Although there doesn't seem to be any problem with actually including the files, I'm getting errors indicating that the classes themselves can't be found when I try to create an instance of them. This only happens if I require the files via an url, as compared to an absolute path. Any idea why the URL form wouldn't work? url_fopen and url_include are both on in my server configuration. Any help is appreciated! Thanks!
  3. Without seeing the error output that your code generates, its a little hard to make any really good suggestions, but I do have the following for you...First of all, save yourself some headache and convert all those mssql_fetch_row calls to mssql_fetch_array. That'll let you reference the fields in your database by name, rather than by number, ie: <?php while ($row = mssql_fetch_array($result){ $machine_name = $row['name']; $application = $row['app']; } ?> Not a big thing, but a huge help to aid clarity, and since PHP handles all arrays as hashes, you won't see a performance hit for using named keys rather than scalars. Next thing I could suggest, and unfortunately, I don't have the time to unknot the ball of yarn myself right now, but you should consider refactoring your code to eliminate some of the nested looping. Perhaps pull the data from your database in to an array, and then use for each to cycle all of the output of the first query through your next query, and so on? Again, not a huge improvement, but splitting things out like that might make it easier for you to see what's going on.
  4. Good call on the html meta tag, that fixed the problem :-). I kinda figured it was going to be a simple gotcha like that. As for using simpleXMLElement...As soon as my hosting flips over to PHP 5, I'll definitely give it a shot...Looks a heck of a lot simpler than xml_parser... Thanks!!
  5. Hi All! I've put together a pretty simple script for reading and displaying RSS feeds, but the trouble I'm having is that some of the characters in the resulting feeds come out all garbled...I figure its a problem with encoding, (I've explicitly set it to UTF-8 in my code), but I have no idea what the solution might be. Relevant code posted below for your review: <?php function Read($feed) { global $items; $parser = xml_parser_create("UTF-8"); // Set the functions to handle opening and closing tags xml_set_element_handler($parser, "startTag", "endTag"); // Set the function to handle blocks of character data xml_set_character_data_handler($parser, "characterData"); $data = file_get_contents($feed); xml_parse($parser, $data, true); xml_parser_free($parser); ... ?>
  6. You're on the right track as far as looking at regular expressions, but aschk has point...regex can be kind of tricky, so its best to "put together" a regex piece by piece, comparing it against a sample file. If you want a somewhat smoother method of checking your regular expressions, there's plenty of software out there that will allow you to test your regex against a sample, just do a quick search on Google. The regex I use in the following example may not work for you...if not, reverse engineer it a little bit, (paying attention to any line feeds in your file...those can mess with regular expression matching), and see what you come up with. <?php $contents = file_get_contents(customer_file.txt); $regex = '/^[a-z0-9.-_]+@[a-z0-9.-_]+\.[a-z]{2,4}$/'; $eval = preg_match($regex, $contents, $matches); if ($eval) { echo "The email in this file is ".$matches[0]; } ?> The key to the whole thing here is the $matches variable, that you pass as a third argument to preg_match. $matches is an array that holds any matches (go figure), to your test pattern. I'm not 100% sure on this, but I believe that your first complete match is found in $matches[0], that'll be the email you're looking for. Hope this helps!
  7. if (file_exists($dir)) { echo "The hub $dir exists already"; } else { echo "Your file doesn't exist, this is an error message" } You didn't provide any circumstances under which the file *would* be created, so barring any case where you'd want to, the above code would do what you described.
  8. Hi All! I've got an issue that has me utterly baffled, and I was hoping that someone here might be able to give me some advice...I've got a web site, http://www.my-linkpage.com, for which I have created a sign-up script. The sign-up process is very straightforward... 1. User fills out form with their information. 2. If the requested user name does not already exist in the database, the user's information is added. 3. The user is sent an email address with instructions for validating their account, (Click here to activate type stuff). 4. User is validated in the system, and can then log in. Everything works, except step 3. I combine sending the email and adding their information to the database in to one script, but whereas the database inclusion works like a charm, the email doesn't get sent. The mail() function returns true, so I'm guessing its an issue in my code, but I copied the darned code word for word out of a script I had built that was already working, so I'm totally at a loss. If someone could take a look at my code and tell me where they think I'm going wrong, I'd appreciate it. Thanks!! <?php require_once('scripts/connect.php'); require_once('scripts/validation.php'); error_reporting(E_ALL); $error_msg=""; if (isset($_POST['submit'])) { //Post Variables: Stripped of all dangerous characters. $Name=mysql_real_escape_string($_POST['sName']); $Email=mysql_real_escape_string($_POST['uEmail']); $UserName=mysql_real_escape_string($_POST['uName']); $Password=mysql_real_escape_string($_POST['uPass']); //Input Validation : We've got to make sure they put something in each box. $is_name=CheckEmpty($Name); $is_email=CheckEmpty($Email); $is_user=CheckEmpty($UserName); $is_pass=CheckEmpty($Password); if (!$is_name||!$is_email||!$is_user||!$is_pass) { $error_msg="<span style='font-color:red; font-weight:bold;'>Please fill out all fields before submitting your registration.</span>"; } else { //No Duplicate UserNames : We've got to connect to the database and make sure that the user name they have selected is not the same as //any other username in the database. $verify_sql="SELECT * FROM tbl_users WHERE UserName='$uName'"; $result=mysql_query($verify_sql); if (mysql_num_rows($result)!=0) { $error_msg="<span style='font-color:red; font-weight:bold;'>That User Name is already taken. Please enter another one.</span>"; } else //If we're okay, then we need to both add the user to the database *and* send them the email that will allow them to //confirm their account. { //Create confirmation hash : MD5 the password $confirm_hash=md5($uPass); //Send Email //Email Headers $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: admin@my-linkpage.com'. "\r\n"; //Email address to send the message to: $EmailTo=$Email; //The Subject Line of the email $Subject="Sign Up Details for My-LinkPage.com"; //Our Message is equal to our content post. $Message="A Message<br />"; //$Success = mail ($EmailTo,$Subject,$Message,$headers); $Success = mail ($EmailTo,$Subject,$Message); if ($Success==true) { header("Location: http://www.thoughtsandrambles.com/contact/thankyou.php"); } else { header("Location: http://www.thoughtsandrambles.com/contact/messagefailed.php"); } //Post to Database. //$post_SQL="INSERT INTO tbl_users (UserName,UserPass,UserNick,UserEmail,UserCode) VALUES ('$UserName','$Password','$Name','$Email','$confirm_hash')"; $post_success=1;//mysql_query($post_SQL); if ($post_success) { //If everything is posted correctly, we send them to the Thank You page. echo "Normally going to thank you page."; echo "$EmailTo<br />$Subject<br />$Message<br />$headers<br />"; } else { //Will go to failure page after we've tested echo ("Could not add to the database<br />".mysql_error()); } } } }//End ISSet Submit ?> <html> <head> <link rel="stylesheet" type="text/css" href="styles/lenderhomepage.css" media="screen" /> <title>Personal Link Page - Login</title> </head> <body> <div id="pagewrap" style="width:800px; height:600px;"> <h2>Sign Up For An Account</h2> <p align="left"> Fill out the form below to register for a My-Linkpage.com account. Once you've completed the sign-up process, you can start creating your own links page. Please note that we require your email in order for you to verify your identity and complete the sign up process, and your email will not be used for any other purpose. For more information, please view our <a href="http://www.my-linkpage.com/documents/tos.html">terms of service</a>. </p> <p><?php echo ($error_msg); ?></p> <div style="margin-left:auto; margin-right:auto; text-align:center;"> <form name="sign-up" method="post" action="#"> <table> <tr><td align="right">Your Name:</td><td><input type="text" name="sName" size="40" /></td></tr> <tr><td align="right">Your Email:</td><td><input type="text" name="uEmail" size="40" /></td></tr> <tr><td align="right">Select A UserName:</td><td><input type="text" name="uName" size="40" /></td></tr> <tr><td align="right">Select A Password:</td><td><input type="password" name="uPass" size="40" /></td></tr> <tr><td align="center" colspan="2"><input type="submit" name="submit" value="Register Now" /></td></tr> </table> </form> </div> </div> </body> </html>
  9. The answer to your question is "Yes", and...if the example you provided is the practical use you had in mind...the extension to that answer is "there are easier ways"...Most good text editing software, comes with features that allow you to do word counts for specific words, so I'd just recommend feeding your essay in to a program like that if that's what you need the function for. Otherwise, if you've got a broader idea in mind, the answer to your question lies in the use of Regular Expressions for text matching...using the preg_match() in PHP, you can match a specific string pattern, and return every match to that pattern in to an array...If Regular Expressions are a new idea to you, I highly recommend that you take a look at http://www.regular-expressions.info/. They've got some great tutorials and reference on using regular expressions that should really help you. Once you understand them, you can just look at the PHP manual for information about preg_match.
  10. Close, but no cigar . A session variable is not really all that different from any other variable, and it could be used in your SQL statement just like any other...However, the syntax would be easier like this: <?php //Assign the session value to a local variable...just my habit, optional if you want to just use $_SESSION directly...I just think this makes for cleaner coding. $user_id=$_SESSION['user'] //Create SQL Statement...The SELECT statement has to be formatted like this...caps are optional...again, my habit is to ALL CAP any SQL keywords. $SQL= "SELECT * FROM mytable WHERE usernumber=".$user_id; ?> That easy
  11. You could have it on the same page, but that might get a bit crowded. It would go something like this, (I'm creating my own example here, hopefully you can adapt this for yourself.) <?php if ($_SERVER['REQUEST_METHOD']=="GET" && $_GET['Item']!="") //If we are passing $GET variables to our script via a URL... //And the "Item" $GET variable is not blank, we know that the //user has clicked one of the "Delete" links. { //Create the SQL Delete Statement: $SQL="DELETE FROM stixy WHERE stixy='".$_GET['Item'}; $result=mysql_query($SQL); //Run the SQL... //Done. } echo "<li>".$row['stixy']." <a href='samepage.php?Item=".$row['stixy']."'>delete record</a>"; //We're linking to the same page we're on, but with $GET variables in our URL...see above ?>
  12. I believe the relevant line of code, (the bit that displays the items you'd like the delete link to appear next to), is this one? echo "<li>"; echo $row['stixy'] . "</li>"; An example of what you're trying to accomplish may be... echo "<li>".$row['stixy']." <a href='delete.php?Item=".$row['stixy']."'>delete record</a>"; Of course, the above pre-supposes that you've got a script called 'delete.php' that can take "Item" as an argument, and that will use that argument to reference the record in the database that you want to delete, and then delete it...I really hope this makes sense!
  13. Hmm...I'm going to have to try that one Charlie... This one is fairly simple, actually readable...and hasn't screwed up on me yet... '/^[a-z0-9.-_]+@[a-z0-9.-_]+\.[a-z]{2,4}$/'
  14. Hmm...I didn't know that, and it's much more efficient...
  15. Are you saying that you'd like to send someone an HTML form via email? Your question is a little vague for anyone to be very helpful.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.