Jump to content

stlewis

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by stlewis

  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.
  16. Assuming your scenario...a text file with the codes in it, seperated by commas: if ($all_correct) //Fire only if we know they got all questions right... { $file="codes.txt"; $f_handle=fopen($file,"r"); //Open the file for read only. $f_size=filesize($file); //Get the size of the file in bytes. $f_contents=fread($f_handle,$f_size); //Read the entire contents of the file in to a variable. $code_array=explode("," , $f_contents); //Explode the contents in to an array $array_count=count($code_array); //Count the number of members in the array /* Now you need to select one of your array elements randomly. Basically, that's just a number between 0, and the total number of elements in your array, (minus 1, because of the 0-based index of an array) */ $random_code=$code_array[rand(0,$array_count-1)]; //Select the random array member. echo $random_code; //Echo the value back. } Hope that helps?
  17. Unfortunately, if you're POSTing to a server/page that you don't have editing control over, there's no way for you to initiate a redirect from that page. The problem is that once you've posted, you've left your original script, so nothing you write in that script can cause a redirect after you post. If you can't edit the page that your information gets posted to, then I'm afraid you're SOL.
  18. Hey! Honestly, I don't have a lot of time to analyze what you've got here...but here's a test...I've attached a mail script that I know works 100% of the time, you've just got to "fill in the blanks" so to speak...give this a go on the server, if it works, then see if you can figure out what's different in your code...if it doesn't, then it's something on the server. Peace. [attachment deleted by admin]
  19. Carl, I think you'll answer 99% of the questions you have if you just do some looking around on how to send HTML formatted emails. It's actually remarkably easy to do, once you get the hang of it. I'm afraid I can't think of any really good resources right off hand that teach one how to do it, but I do have here a generic script for sending HTML email...it's pretty well commented, so if it's of use to you, it's yours with my compliments [attachment deleted by admin]
  20. I'm afraid you've described your problem a bit ambiguously...do you mean to say that your SQL UPDATE statement does not appear to be working? Is it returning some kind of error? I glanced over your script, and one thing you might consider adding is something to this effect: $update_successful=mysql_query($query); if ($update_successful) { //Do stuff intended when the update goes well... } else { die("Could not update the record<br />".mysql_error()); } That way, if your SQL statement fails for any reason, you can find out the reason why by echoing the mysql_error(); method.
  21. Well, in the code that you've displayed there, you've got no anchor text for the URL, so technically, nothing would display. If $result is a collection of data that you've pulled in from a database search, make sure that the data you're echoing back is actually a URL too :-)
  22. Why is it that you go to the trouble of creating a variable to hold your new file name, "$uploadFilename" but your IF statement tests (..smallpics/".$a.$name..) Shouldn't it be: if(imagejpeg($thumb, "$uploadFilename, 80)) { //image-resource, filename, quality return 1; } That might help a bit, sorry if it doesn't!
  23. Actually, depending upon how expansive your information is going to become, you might consider using a database anyway. This seems like the kind of application that would need one...that way you could relationally store information about a particular item's author, genre, whatever...As for generating a playlist out of database information...You could technically query your database, and then output the queried data in to a flat file for use as a playlist: $q = "SELECT * FROM tbl_songs"; $q_result=mysql_query($q); //Open or create flat playlist file. $f_handle=fopen("playlist", "w+"); while ($q_array=mysql_fetch_assoc($q_result)) { //Feed the contents of the SQL query in to variable $content=$content.q_array[songName]; } //Write the final contents out to the flat file. fwrite($f_handle,$contents); Sorry if I'm misunderstanding you here!
  24. Actually, (and please correct me if I'm wrong...I'd like to be wrong about this, as it would make my life easier...but the readdir() function doesn't work on a remote server, hence the error. The script needs to reside in the same server as the directory you want to read.
  25. Just open the log file in apend mode; fopen($file,"a+"); Whatever you write to the existing file is placed at the end...done.
×
×
  • 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.