[PHP] Re: Question about using if elseif ...
Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Question about using if elseif ...
When viewing examples of using if and elseif I often see the example ending with an else like ... if($a == '1'){ echo '1'; } elseif ($a == '2'){ echo '2'; } else { echo '0'; } Is there any problem with leaving out the last else and just ending it with an elseif such as ... if($a == '1'){ echo '1'; } elseif ($a == '2'){ echo '2'; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
Thanks for pointing me in the right direction. Could not get the output (success or failure) assigned to a variable in front of the system call but got it to assign a 0 (success) or 1 (failure) to the return_var argument as you suggested so I am happy. ?php system(mysql -u myuserid -pmypassword mydbname /path/to/mydumpfile.txt, $status); if($status == 1){ echo 'Failed'; } else { echo 'Success'; } ? What mixed me up and I still don't understand is the manual entry for system() says ... Returns the last line of the command output on success, and FALSE on failure. When it says it Returns, where does it return this information and how can it be captured for comparison? The return_var appears to only return a 0 or a 1. I thought I could capture it by assigning the system call to a variable in front but that appears to capture nothing on success or failure. Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Tue, Jul 09, 2002 at 10:59:04PM -0700, Fargo Lee wrote: Thanks but it still returns Success on a failure. If anyone knows if it is even possible to assign the output of system, passthru or exec to a variable to check for success or failure and how to do it, please advise. The $status variable seems to always be empty on success or failure when I try to echo it. The way you set things up, $status is the last line of text returned by executing the command. Add the return_var argument to your system() statement. Take a look at the manual again. http://www.php.net/manual/en/function.system.php You can only make an accurate if() statement if you know what the values are you're expecting. Now, do some hacking. Set up the test to fail. Echo $status and $return to the screen and see what they look like. Set up the test to succeed. What do $status and $return look like then? --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
Yes, on success the command I am issuing does not produce any output on the command line and thus the $status variable should be blank on success. But when made to fail MySQL does return an error on the command line yet the variable does not hold FALSE as the manual suggests it should or anything else. This suggests, as do a few posts I just noticed in the manual, that one cannot assign the output of system() and perhaps passthru() and exec() to a variable. I think this is only possible using backticks, which I can't use as this needs to be run in safe mode. So I guess I just need to use the return_var as you suggested. Thanks! Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Tue, Jul 09, 2002 at 11:41:47PM -0700, Fargo Lee wrote: got it to assign a 0 (success) or 1 (failure) to the return_var argument as you suggested so I am happy. Good! What mixed me up and I still don't understand is the manual entry for system() says ... Returns the last line of the command output on success, and FALSE on failure. When it says it Returns, where does it return this information and how can it be captured for comparison? The thing that's tripping you up is, I believe, executing MySQL programs at a prompt doesn't produce any visible output. But, if you executed a command that returns some output to STDOUT, like ls, you'd see the last line of output therefrom in the Return. --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
Thanks that explains why I did not initially have a space after the -u as I copied the code from another of my applications that used backticks without reviewing it. It appears that using backticks is also the only way to assign the output of a command to a variable as system(), passthru() and exec() don't appear to be able to do this. Unfortunately this snippet of code needs to be compatible with PHP installations running in safe mode so I can't use backticks. John Holmes [EMAIL PROTECTED] wrote in message 021501c22807$a91e42d0$b402a8c0@mango">news:021501c22807$a91e42d0$b402a8c0@mango... Try using backticks, and you don't need spaces after -u and -p $result = `MySQL -uuser -ppassword databasename filename.sql` Note that if it succeeds, nothing will be returned. Same as when you run the command on the command line. ---John Holmes... -Original Message- From: Fargo Lee [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 1:27 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] How do I import tables into MySQL from web page ... Thanks for pointing out the syntax error. I added the space after the -u but it did not make any difference. It still gives the same result, that is Success, when it actually fails. What I am trying to figure out is how I can tell if it failed (did not create the tables)? The $status variable does not appear to hold the output of the system() function. Anyone know how to get the output of system, passthru or exec into the $status variable to check for success or failure? Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Tue, Jul 09, 2002 at 06:09:36PM -0700, Fargo Lee wrote: $status = system(mysql -umyuserid -pmypassword mydbname You need a space between -u and myuserid --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
I ran a few tests as well and the few system commands I tried only saved the *last* line of the output in a variable on success as the manual suggests it should - better than nothing - but not the entire output as you seem to suggest you were able to do and what I have been trying to do. Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Wed, Jul 10, 2002 at 12:14:58PM -0700, Fargo Lee wrote: This suggests, as do a few posts I just noticed in the manual, that one cannot assign the output of system() and perhaps passthru() and exec() to a variable. I forgot to mention, that's not accurate. I just ran a test to make sure. Got the results just fine. Just for clarity, here's my test (PHP 4.2.1, NT 4.0): # real directory. # result: output shows file list, false no, return 0 # $output = system('dir c:\books', $return_var); # fake directory. # result: output shows nothing, false yes, return 1 $output = system('dir y:\fake', $return_var); echo output: $output; echo 'hr /'; echo 'output false? ' . ( ($output == FALSE) ? 'yes' : 'no' ); echo 'hr /'; echo return: $return_var; --Dan I think this is only possible using backticks, which I can't use as this needs to be run in safe mode. So I guess I just need to use the return_var as you suggested. Thanks! Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Tue, Jul 09, 2002 at 11:41:47PM -0700, Fargo Lee wrote: got it to assign a 0 (success) or 1 (failure) to the return_var argument as you suggested so I am happy. Good! What mixed me up and I still don't understand is the manual entry for system() says ... Returns the last line of the command output on success, and FALSE on failure. When it says it Returns, where does it return this information and how can it be captured for comparison? The thing that's tripping you up is, I believe, executing MySQL programs at a prompt doesn't produce any visible output. But, if you executed a command that returns some output to STDOUT, like ls, you'd see the last line of output therefrom in the Return. --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
But if system() thinks it is a success because the command executed, even though MySQL returns an internal error on the command line, why is'nt the last line of the MySQL error message stored in the variable as the system() manual suggests it should be when system() thinks it is a success? Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Wed, Jul 10, 2002 at 12:14:58PM -0700, Fargo Lee wrote: when made to fail MySQL does return an error on the command line yet the variable does not hold FALSE as the manual suggests it should or anything else. The behaviour of returning FALSE upon failure has to do with the system() call not being able to be made due to things like the command itself not being able to execute, such as when the name of the program is wrong. But, since the program in this case actually executed, there's no failure. --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
Run the command manually at a shell prompt. What happens? Here's what happens for me on WinNT. In an error condition, say my password is invalid, it retuns the error message then a blank line and then I'm back at the prompt. So, if system() is true to the manual, that blank line is the last line, so it's the one that gets put into the variable. My bad, it is a blank line after the error message on my system too. I missed the blank line last time, I need some glasses. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I import tables into MySQL from web page ...
Hi, I am trying to import some tables from a dump file into a MySQL database from a php web page. What is the best way to do this without using backticks (fpassthru, system, exec or something else) and test for success or failure? I tried the following and while it works, my test for success or failure always produces a Success even when I change something to make it fail. I thought system() outputs the last line of the command on success and FALSE on failure. Any examples appreciated. ?php $status = system(mysql -umyuserid -pmypassword mydbname /path/to/mydumpfile.txt); if($status == 'FALSE'){ echo 'Failed'; } else { echo 'Success'; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
Thanks for pointing out the syntax error. I added the space after the -u but it did not make any difference. It still gives the same result, that is Success, when it actually fails. What I am trying to figure out is how I can tell if it failed (did not create the tables)? The $status variable does not appear to hold the output of the system() function. Anyone know how to get the output of system, passthru or exec into the $status variable to check for success or failure? Analysis Solutions [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Tue, Jul 09, 2002 at 06:09:36PM -0700, Fargo Lee wrote: $status = system(mysql -umyuserid -pmypassword mydbname You need a space between -u and myuserid --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I import tables into MySQL from web page ...
Thanks but it still returns Success on a failure. If anyone knows if it is even possible to assign the output of system, passthru or exec to a variable to check for success or failure and how to do it, please advise. The $status variable seems to always be empty on success or failure when I try to echo it. Jason Wong [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On Wednesday 10 July 2002 13:27, Fargo Lee wrote: Thanks for pointing out the syntax error. I added the space after the -u but it did not make any difference. It still gives the same result, that is Success, when it actually fails. What I am trying to figure out is how I can tell if it failed (did not create the tables)? The $status variable does not appear to hold the output of the system() function. Anyone know how to get the output of system, passthru or exec into the $status variable to check for success or failure? Your test for failure should be: if ($status === FALSE) -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Extreme fear can neither fight nor fly. -- William Shakespeare, The Rape of Lucrece */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I hide download link ...
Thanks for the code, I think I am getting there but an empty file gets downloaded when I load the following script. See any problems? ?php $filename = backup.tar; $download_file = /absolute/path/backup.tar; header(Content-Type: application/x-tar); header(Content-Disposition: attachment; filename=$filename); passthru($download_file); exit(); ? I verified my server is setup to handle tar files with application/x-tar. I also replaced ... header(Content-Type: application/x-tar); with header(Content-Type: application/octet-stream); and it did not make a difference. I am using IE 6 if it matters. Any ideas? 1lt John W. Holmes [EMAIL PROTECTED] wrote in message 00c401c216d4$4fc1bd50$2f7e3393@TB447CCO3">news:00c401c216d4$4fc1bd50$2f7e3393@TB447CCO3... I thought we answered this question already! It's simple. On your login page or whatever, you start a session and set a variable saying that the user is logged in. ? session_start(); //check username and password //if good... $_SESSION['logged_in'] = 1; ? Now, the most secure way to protect your files is to place them above your web root. Then no one can ever get to them through a browser (directly to the file). If you can't do that, then place them in a folder with a long name that's going to be hard to guess. Then, you have a download.php file that you direct all requests for downloads to. You'll also have to pass it a code to identify which file the user means to download. This can be an ID from a database, or an actual filename. download.php?ID=4 download.php?Filename=music etc... In download.php you check for an active session. If it's good, then you send the appropriate header() for the file the user wants to download and then use passthru() to send them the file. Make sure you are only sending them a file from your download directory, wherever that is. Make sure they don't pass you a path to a file they shouldn't be looking at. ? session_start(); if(isset($_SESSION['logged_in'])) { //session is good //retrieve name of file (whether in URL or Database $file = $_GET['Filename'] . .mp3 $download_dir = /home/user/me/downloads/music/ $download_file = $download_dir . $file header(content-type: application-whatever-mp3-x); header(content-disposition: attachement filename='$file'); passthru($download_file); exit(); } else { echo htmlbodyPlease log in/body/html; } ? I don't remember the exact header() format, and it's dependent on the types of files your offering, but you should get the idea. Adapt to your needs, but this is the basics of it. Check for a valid session, if it exists, send appropriate headers and use passthru() to send the file. (you can use file(), fopen(), whatever, as long as you send the content of the file after the headers...). If session doesn't match up, send an HTML page. Hopefully this thread will die now... ---John Holmes... - Original Message - From: Nathan Taylor [EMAIL PROTECTED] To: Fargo Lee [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, June 18, 2002 5:42 AM Subject: Re: [PHP] How do I hide download link ... - Original Message - From: Fargo Lee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 12, 2002 4:14 PM Subject: [PHP] How do I hide download link ... Hi, my customers go through a password authentication to access a link on my site to download a file. I want to prevent the distribution of the location of this file on my server by making it hidden. Is there any php function(s) that could assist in doing this? All I can think of so far is storing the original file in a hard to guess directory, when a authenticated customer goes to download it, send them to a script that copys the original file to a temp directory, they download the file in the temp directory and then run a cron every so many minutes to clear out the files in the temp directory. If anyone has any ideas, examples or a way to improve on what I came up with please respond. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I hide download link ...
Hi, if using the header command for attaching a file really prevents the user from seeing the actual download link, is it really all that important that the file is read from behind the document root if it is in a very hard to guess directory? Martin Towell [EMAIL PROTECTED] wrote in message news:6416776FCC55D511BC4E0090274EFEF508A4B5@EXCHANGE... Have a page that checks the user's authentication if they're invalid then display an error msg and exit the script otherwise, send the header command(s) for attaching a file (can't remember the exact syntax right now) read the file from somewhere that's not accessable from the web and spit it out to the browser HTH Martin -Original Message- From: Fargo Lee [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 13, 2002 6:15 AM To: [EMAIL PROTECTED] Subject: [PHP] How do I hide download link ... Hi, my customers go through a password authentication to access a link on my site to download a file. I want to prevent the distribution of the location of this file on my server by making it hidden. Is there any php function(s) that could assist in doing this? All I can think of so far is storing the original file in a hard to guess directory, when a authenticated customer goes to download it, send them to a script that copys the original file to a temp directory, they download the file in the temp directory and then run a cron every so many minutes to clear out the files in the temp directory. If anyone has any ideas, examples or a way to improve on what I came up with please respond. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I hide download link ...
Ok think I am all good now. Added ... $fh = fopen($download_file, r); then changed ... passthru($download_file); to fpassthru($fh); Thanks, again! Fargo Lee [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Thanks for the code, I think I am getting there but an empty file gets downloaded when I load the following script. See any problems? ?php $filename = backup.tar; $download_file = /absolute/path/backup.tar; header(Content-Type: application/x-tar); header(Content-Disposition: attachment; filename=$filename); passthru($download_file); exit(); ? I verified my server is setup to handle tar files with application/x-tar. I also replaced ... header(Content-Type: application/x-tar); with header(Content-Type: application/octet-stream); and it did not make a difference. I am using IE 6 if it matters. Any ideas? 1lt John W. Holmes [EMAIL PROTECTED] wrote in message 00c401c216d4$4fc1bd50$2f7e3393@TB447CCO3">news:00c401c216d4$4fc1bd50$2f7e3393@TB447CCO3... I thought we answered this question already! It's simple. On your login page or whatever, you start a session and set a variable saying that the user is logged in. ? session_start(); //check username and password //if good... $_SESSION['logged_in'] = 1; ? Now, the most secure way to protect your files is to place them above your web root. Then no one can ever get to them through a browser (directly to the file). If you can't do that, then place them in a folder with a long name that's going to be hard to guess. Then, you have a download.php file that you direct all requests for downloads to. You'll also have to pass it a code to identify which file the user means to download. This can be an ID from a database, or an actual filename. download.php?ID=4 download.php?Filename=music etc... In download.php you check for an active session. If it's good, then you send the appropriate header() for the file the user wants to download and then use passthru() to send them the file. Make sure you are only sending them a file from your download directory, wherever that is. Make sure they don't pass you a path to a file they shouldn't be looking at. ? session_start(); if(isset($_SESSION['logged_in'])) { //session is good //retrieve name of file (whether in URL or Database $file = $_GET['Filename'] . .mp3 $download_dir = /home/user/me/downloads/music/ $download_file = $download_dir . $file header(content-type: application-whatever-mp3-x); header(content-disposition: attachement filename='$file'); passthru($download_file); exit(); } else { echo htmlbodyPlease log in/body/html; } ? I don't remember the exact header() format, and it's dependent on the types of files your offering, but you should get the idea. Adapt to your needs, but this is the basics of it. Check for a valid session, if it exists, send appropriate headers and use passthru() to send the file. (you can use file(), fopen(), whatever, as long as you send the content of the file after the headers...). If session doesn't match up, send an HTML page. Hopefully this thread will die now... ---John Holmes... - Original Message - From: Nathan Taylor [EMAIL PROTECTED] To: Fargo Lee [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, June 18, 2002 5:42 AM Subject: Re: [PHP] How do I hide download link ... - Original Message - From: Fargo Lee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 12, 2002 4:14 PM Subject: [PHP] How do I hide download link ... Hi, my customers go through a password authentication to access a link on my site to download a file. I want to prevent the distribution of the location of this file on my server by making it hidden. Is there any php function(s) that could assist in doing this? All I can think of so far is storing the original file in a hard to guess directory, when a authenticated customer goes to download it, send them to a script that copys the original file to a temp directory, they download the file in the temp directory and then run a cron every so many minutes to clear out the files in the temp directory. If anyone has any ideas, examples or a way to improve on what I came up with please respond. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to convert seconds to days, hours, minutes seconds?
Thanks! Fargo Lee [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Hi, if I have a variable containing a number of seconds what function would I use to output something like ... 13 Hours, 12 Minutes, 3 Seconds or 23 Days, 13 Hours, 12 Minutes, 3 Seconds Any examples appreciated, thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php