Jump to content

txmedic03

Members
  • Posts

    313
  • Joined

  • Last visited

Everything posted by txmedic03

  1. No not at all. What was meant by using $_SERVER['HTTP_REFERER'] is something like if you have poll.php which contains your poll and you have writepoll.php which is where your information gets sent then you could have a message that upon success says: [code] echo "Thanks for your opinion, click <a href=\"".$_SERVER['HTTP_REFERER']."\">here</a> to return to where you came from.\r\n"; [/code] You could use a redirect if you have not sent output to the browser already like this: [code] head("Location: ".$_SERVER['HTTP_REFERER']); [/code] A javascript redirect would do the job too, but let's concentrate on the PHP solutions since some people disable javascript in their browser and we want the pages to be as universal as possible. Now if your poll.php is the poll as well as the file that will process it you could do something like this. [code] <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">   {Poll form elements go here per usual} </form> [/code] This will submit the value(s) to the current page and then poll.php can process them. Make sure your code to process the form is placed above the form in you poll.php file so you can pick whether to display the poll or perhaps a print out of the votes cast so far. Also be aware if you have other forms on any of your pages that your scripts must be able to determine if they are the one being submitted or not. If you use the $_SERVER['REQUEST_METHOD'] to determine if the form was posted and two forms on the page were both using "POST" method things could get a little tricky. I hope I have pointed you in the right direction, but if not, please, let me know I will try to rectify the situation. Happy coding!
  2. because \$ is the escape for a $ rather than print a variable it prints the $ followed by the variable name. the simple solution is: [code] <?php $source_file = 'copy/index.php'; $dest_file = 'F:\iTunes\'.$file.'\index.php'; copy($source_file, $dest_file) or die("Failed!"); echo "Success!"; ?> [/code] Provided the server can access (F:) to write the file everything should work fine now. Happy coding!
  3. If all you want to know is the age in years then exact age is not important, but I think I have a script that will fit your need. Assuming the following code is in age.php date should be passed as age.php?date=6/5/1988 You can change the way it gets the date to suit your needs, but the basic idea is here. This is just what I came up with off the top of my head. There are probably a handful of ways to do it. [code] <?php $arr1 = explode("/",$_GET['date']); $arr2 = array(date("m"),date("d"),date("Y")); $year = $arr2[2] - $arr1[2]; if ( ( $arr1[0] > $arr2[0] ) || ( ( $arr1[0] = $arr2[0] ) && ( $arr1[1] < $arr2[1] ) ) ) $year = $year - 1; echo "<p>User born on ".$_GET['date']." is ".$year." years old.</p>\r\n"; if ( $year < 21 ) echo "<p>User is under 21.</p>\r\n"; if ( $year < 18 ) echo "<p>User is a minor.</p>\r\n"; ?> [/code] I hope this helps. Happy coding!
  4. [!--quoteo(post=352433:date=Mar 7 2006, 03:49 AM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Mar 7 2006, 03:49 AM) [snapback]352433[/snapback][/div][div class=\'quotemain\'][!--quotec--] hmmm... maby if you run your own mailserver you should try sending an email to a local domain like yourname@yourdomain.com also look at the sendmail log to see if there is an error there. There are lots of log analysers out there that you can use just search google for sendmail log [/quote] Actually I could run SMTPd, POP3d, POP2d and/or IMAP4d; but currently I am not. I was under the impression that the idea was you didn't need a SMTPd if you had sendmail. I will check the sendmail log, though. Thanks for the tip. If I get this resolved soon I can go back to working on my scripts and be a happy little coder.
  5. Yes, it is possible to extend the max execution time of a script, but alternatively, how about one script that parses your data in blocks. It is just a thought, but it will keep you from executing your script for a long period of time. for instance create the script to copy the first $x number of rows then head("Location: ".$_SERVER['PHP_SELF']."?n=".$num); // $num is the beginning of your next block of x rows Then you are back on the same page except now you have $_GET['num'] to tell you where to start to copy rows $num through $num + $x to your database. Make it continue to use head() until you run out of entries. Just make sure there is no output to the browser or you can't send headers. This is just one possibility that came to mind since your server may not allow you to extend your timeout on execution. Your server may specifically restrict it because of the obvious effects it has on the server. They may not like it.
  6. That depends on how you pass the variables to your page. Is $page supposed to be something like index.php?page=0? If this is the case I would suggest using $_GET['page'] because your server may not be configured to use $page. It is safer that way and it is a better coding practice to go for a universal compatibility. Additionally, if you are interested, I could make suggestions on ways to possibily simplify your script. Only if you are interested in my help. Happy coding! P.S. You can install Apache on windows platforms. I personally prefer working with Apache.
  7. Well I would need more information about the form to give you an exact script to demonstrate how to cover your particular issue, but simply put after you process the form for errors there are two ways that spring to mind. Number one is if the form is on form.php and it is also the action, that is the form.php file also processes the form. Then you can use your $_POST array. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="text" name="field1" id="field1" value="<?php echo $_POST['field1']; ?>" /> <input type="submit" value="Test" /> </form> Let's just say for simplicity of this example that you want to make sure that whatever was entered into the form was at least 5 characters long. If this were the case you could place this PHP block above your form: <?php if ( ( $_SERVER['REQUEST_METHOD'] == "POST" ) && ( strlen($_POST['field1']) < 5 ) ) { echo "<p>ERROR! field1 must be at least 5 characters.</p>\r\n"; } ?> This simply checks to make sure your form has been submitted and if field1 is less than 5 characters long it tells the user they messed up. Then your form will contain the previous user input. You may want to not display the form if they get everything correct or simply redirect to another page if they get everything correct. You can use the if statement to stop the form from being displayed or a head() to redirect on success. Now I meantioned that two ways sprank to mind earlier. The second way is with two separate files where form.php is your form and process.php is the file that actually processes the user's input. Your form.php would be something like this: <form action="process.php" method="POST"> <input type="text" name="field1" id="field1" value="<?php echo $_GET['field1']; ?>" /> <input type="submit" value="Test" /> </form> Again we will assume that field1 is too short for this example. Now with a redirection on error back to the form you can do this: <?php if ( strlen($_POST['field1'] < 5 ) { head("Location: form.php?field1=".$_POST['field1']); } else { echo "Hey, good job!\r\n"; } ?> If you don't want to just use a redirection you could give the user a link to go back to the form. <?php if ( strlen($_POST['field1'] < 5 ) die("<p>You didn't put enough characters in field1.<br />Please go back and <a href=\"form.php?field1=".$_POST['field1']."\">try again</a>.</p>"); echo "Success!"; ?> In these last two examples I assumed that the page would not be viewed without having the form post to it, but if you wish you can use the REQUEST_METHOD from the first example for good measure. In this last example I used a die statement rather than if then else format. This is perfectly acceptable as is the if then else format. It will come down to a matter of personal preference. Happy coding!
  8. Well I would need more information about the form to give you an exact script to demonstrate how to cover your particular issue, but simply put after you process the form for errors there are two ways that spring to mind. Number one is if the form is on form.php and it is also the action, that is the form.php file also processes the form. Then you can use your $_POST array. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="text" name="field1" id="field1" value="<?php echo $_POST['field1']; ?>" /> <input type="submit" value="Test" /> </form> Let's just say for simplicity of this example that you want to make sure that whatever was entered into the form was at least 5 characters long. If this were the case you could place this PHP block above your form: <?php if ( ( $_SERVER['REQUEST_METHOD'] == "POST" ) && ( strlen($_POST['field1']) < 5 ) ) { echo "<p>ERROR! field1 must be at least 5 characters.</p>\r\n"; } ?> This simply checks to make sure your form has been submitted and if field1 is less than 5 characters long it tells the user they messed up. Then your form will contain the previous user input. You may want to not display the form if they get everything correct or simply redirect to another page if they get everything correct. You can use the if statement to stop the form from being displayed or a head() to redirect on success. Now I meantioned that two ways sprank to mind earlier. The second way is with two separate files where form.php is your form and process.php is the file that actually processes the user's input. Your form.php would be something like this: <form action="process.php" method="POST"> <input type="text" name="field1" id="field1" value="<?php echo $_GET['field1']; ?>" /> <input type="submit" value="Test" /> </form> Again we will assume that field1 is too short for this example. Now with a redirection on error back to the form you can do this: <?php if ( strlen($_POST['field1'] < 5 ) { head("Location: form.php?field1=".$_POST['field1']); } else { echo "Hey, good job!\r\n"; } ?> If you don't want to just use a redirection you could give the user a link to go back to the form. <?php if ( strlen($_POST['field1'] < 5 ) die("<p>You didn't put enough characters in field1.<br />Please go back and <a href=\"form.php?field1=".$_POST['field1']."\">try again</a>.</p>"); echo "Success!"; ?> In these last two examples I assumed that the page would not be viewed without having the form post to it, but if you wish you can use the REQUEST_METHOD from the first example for good measure. In this last example I used a die statement rather than if then else format. This is perfectly acceptable as is the if then else format. It will come down to a matter of personal preference.
  9. Okay, one solution that comes to mind is to search the directory for a text file using readdir(). If I am understanding correctly the directory only contains 10-20 songs, a text file and possibly some album art. This should allow for it to parse the contents of the directory rather quickly. $dir = {directory with the unknown TXT file}; // make sure you include a trailing / here or between $dir and $file in future lines of code. function findTXT($dir) { // make sure it is really a valid directory to eliminate errors if (is_dir($dir)) { // make sure we can open the directory with error before we continue if ($dh=opendir($dir)) { // read the directories file/sub dir names one at a time while($file=readdir($dh)) { if (!is_dir($dir.$file)) $ext = substr($file, strlen($file)-3); // make sure $file is not a directory then obtain the extension. if ( strtolower($ext) == "txt" ) return $file; // if the $file extension is txt return the name to be used by your other script } } } } I tried to comment everything out to make it simple and to cover all possible errors that came to mind. I hope this helps you. Happy coding!
  10. You could do something like this. <?php // check to see if the user reached the page by 'POST' method. if ( $_SERVER['REQUEST_METHOD'] == "POST" ) { print_r($_POST); // print the contents of the $_POST array } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="text" id="field1" name="field1" /> <input type="hidden" id="field2" name="field2" value="this is a hidden field." /> <input type="submit" value="Send >>" /> </form> This will submit the values to itself, but the same can be applied by creating a page to process the values separate from the form that sent them. Also note that you may pass values to the $_GET array at the same time you pass variables to the $_POST array by using <form action="<?php echo $_SERVER['PHP_SELF']; ?>?field3=field3"> then in your PHP you would need something like: <?php // Check to see if $_GET is an established array if ( is_array($_GET) ) { print_r($_GET); // print the contents of the $_GET array } ?> You would only need to check to make sure $_GET is actually an array to keep from encurring errors with print_r(). I only use print_r() for simplicity sake and your error handling may vary depending on exactly what you wish to do with your data once you get it from the form. Happy coding!
  11. Well, it all depends on your needs, but I handle all of my sessions with mysql. I use session_start() to begin the session with a unique sid then session_id() to reference the row in the sessions table. Every user has a row in this table so I can track current users viewing the site. If the user does not load any pages with in 10 minutes the row is removed from the table. I do this by using time()+600 and comparing it to time(). if time() >= {value retrieved from mysql for time()+600} then expire delete row from table otherwise update row with time()+600 to continue session for 10 minutes from now. Incidently, you do not have to store your username/password or anything in the $_SESSION since the session_id() returns a unique identifier for your sessions. If you would like more detailed information on the way I did the user tracking and handled the sessions so you can benchmark it against storing data in $_SESSION, let me know and I would be happy to share an example script with you.
  12. I am running a suse linux 9.1 professional box with apache2/php4 and for some reason the mail() function is returning successful, but the messages never reach the destination. I have checked the reference from the php.ini file to the sendmail and it is correct. Is there something more I need to do?
×
×
  • 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.