Jump to content

garyed

Members
  • Posts

    176
  • Joined

  • Last visited

Everything posted by garyed

  1. So what you're saying is that I can put an exec() command on the php page that when it is accessed by another computer it would open up my mp3 player. That sounds simple enough but I'm not sure I know how to do it. I'll give it a try.
  2. This might be more than just a php question but here goes anyways. I have designed a php chat room page on my home Apache server just for a few friends & family. The problem I have is the only way for me to know if anyone is on the chat room page is if I'm actually viewing the php page. Is there a way that I can have the page alert me when someone accesses it? I was thinking something like activating a popup in my browser or even a beep so as long as I'm at my computer with my browser open that I will know someone has accessed the page.
  3. You are the man!! That did it, I removed the white space & it works like a top . I've been working on this for three days & couldn't figure out what I was missing. Thanks again
  4. Also the" xdata/tables.php" is the only path that I'm using but I guess all the path in front is because I'm on a shared server. For security reasons I changed a few numbers in the path but not the format.
  5. Here is the message that is displayed at the top of the same page where the text of the file is displayed:
  6. The code in the last post is pretty much it. That is where the problem lies. I tried taking away the if statement & substituting the name of a table so i could run that file by itself & it works fine on my server. I do the same thing on my web host server & instead of the file downloading it displays the full text of the file on the screen. I'm starting to think that there is nothing wrong with the code & that there is a problem with my web host settings. If you or anyone here using a mysql database can test this code on your server I would appreciate it. <?php $_table="table1"; // gets the table name from first page include ("mysql_login"); // opens mysql with $con as the database variable header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=table.csv'); $output = fopen("php://output", "w"); fputcsv($output, array('id', 'First_name', 'Last_name', 'email', 'phone')); $query = "SELECT * from $_table ORDER BY id ASC" or die ("Help"); $result = mysqli_query($con, $query); while($row = mysqli_fetch_assoc($result)) { fputcsv($output, $row); } fclose($output); ?>
  7. Here is the simpler code that I first used: <?php if(isset($_POST["first_page"])) { $_table=$_POST['table_name']; // gets the table name from first page include ("mysql_login.php"); // opens mysql with $con as the database variable header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=table.csv'); $output = fopen("php://output", "w"); fputcsv($output, array('id', 'First_name', 'Last_name', 'email', 'phone')); $query = "SELECT * from $_table ORDER BY id ASC" or die ("Help"); $result = mysqli_query($con, $query); while($row = mysqli_fetch_assoc($result)) { fputcsv($output, $row); } fclose($output); } ?> This works perfectly on my server. If you enter the link to my server it downloads right into the browser default download directory. It just doesn't work when i upload it to my web host. The same code just prints the .csv file to the screen instead of downloading.
  8. Okay, here goes & it might not be pretty. What I don't understand is if I type in my ip address & the path in my browser it will access my Apache server & mysql db, put the csv file on my server then automatically download it to my default browser directory. That is exactly how I intended for the code to work. When I upload it to my web host then it does everything except download to my computer. Anyways I would much rather do as suggested & never put the file on the server & just directly download it to the user's computer who has the password to access the php fil <?php ///////// Turn table into a .csv file & put it on server //////////////////// if(isset($_POST["first_page"])) // makes sure there is a submit value from the first page { $_table=$_POST['table_name']; // gets the table name from first page include ("mysql_login.php"); // opens mysql with $db as database variable // If statement is for the choice between two tables // Gets the results of the table & puts it in a .csv file on the server if ($_table=="table1") { $output = fopen("table1.csv", "w"); fputcsv($output, array('id', 'First', 'Last', 'email', 'phone')); } else { $output = fopen("table2.csv", "w"); fputcsv($output, array('id', 'First', 'Last', 'email', 'phone')); } $query = "SELECT * from $_table ORDER BY id ASC" or die ("Help it ain't working"); $result = mysqli_query($con, $query); while($row = mysqli_fetch_assoc($result)) { fputcsv($output, $row); } fclose($output); } ///////////////////// download file to user's computer depending on which table was chosen ///// if ($_table=="table1") { $file = './table1.csv'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } else { $file = './table2.csv'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } ?> e.
  9. That's really what I want to do but i can't figure out how to do it. It's only one user that I'm dealing with that I'm doing the site for. They just want to be able to put the contents of the mysql database into an excel spreadsheet. Since the database is changing every day I just want them to be able to login & download any time they want. I've already set it up where they can view the database at any time & I got it where each table can be converted to a csv file for excel but I don't know how to get it so it will download to their computer. That's where I'm stuck. I've been searching online for a way to do it & haven't been very successful. That's why I thought I'd have to download the file to the site first before they could download it to their computer. Any help appreciated
  10. So am i right in assuming that since I'm already using the php file to create & send the .csv file to my server that the only way for the user to download that file using the code I posted in my opening post would be in a separate file?
  11. When I said it spits the text out to the screen, I meant the text of the file(.csv) to be downloaded. The php file makes a .csv file from a database & then puts it on the server so it can be downloaded by the user. I'm trying to do it all in one password protected file. What is happening is instead of the file being downloaded, it's text is being output to the screen. If I put the same code I posted above in a separate php file & point to it from the original php file then everything works as planned.
  12. I think that's the problem but I need all the code I have before it because that it what I use to access the database & create the file that I want the user to download. The funny thing is it all works fine in one single file on my Apache server but when I upload the same code to my web host (1and1), instead of downloading it spits the text out to the screen.
  13. But I don't want use another file to do it. I have a shared hosting package & I'd like to at least keep that info along with a database password in one file.
  14. I have a site where I want another user that has a password fills out a form & it then downloads to my server. I want them to be able to then download that file from my site at the same time the form is submitted. I've tried adding this code to the bottom of the php file that the form points to but it just displays the file on the screen instead of downloading to the user's computer. <?php $file = '/site/downloadfile'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } ?> if I put the same code in a separate file it works perfectly but i don't want to add another file if i can help it. Any help appreciated
  15. Thanks for the clarification, That's exactly what I didn't understand. I didn't know that I could run php through the terminal. When i tried it through the terminal things worked fine but I was trying to run those scripts as a web page through my Apache server so there were no pauses in the execution of the script. I nested an html button to do what i needed inside the php code but I wanted to experiment to see if i could do a pause with php until the user is ready. What i'm really doing is having a script to encode a session & I wanted a pause to give the user time to write the filename down they chose before returning them to another page.
  16. So you're saying it can't be done through php without using a client side scripting language. I didn't think it could but when I saw these different codes online it sure looked like people were doing it with php alone. Can you explain how any of those codes work or are they all wrong?
  17. I've been trying to pause a php script until a key is pressed by the user & I can't get it working. I've found quit a few answers online that seem to work for everyone else but not on my system. I'm running: PHP Version 5.5.9-1ubuntu4.5Below is a few of the codes I have tried but none of them accept any input & just run the script straight through to the end of the code. <?php echo "Are you sure you want to do this? Type 'yes' to continue: "; $handle = fopen ("php://stdin","r"); $line = fgets($handle); if(trim($line) != 'yes'){ echo "ABORTING!\n"; exit; } echo "\n"; echo "Thank you, continuing...\n"; ?> ------------------------------------------ <?php echo "Enter your name\n"; // Output - prompt user $name = fgets(STDIN); // Read the input echo "Hello $name"; // Output - Some text exit(0); // Script ran OK ?> ------------------------------------------------- <?php function anykey($s='Press any key to continue...') { echo "\n".$s."\n"; fgetc(STDIN); } anykey; echo "Help"; ?> ------------------------------------------------------- <?php define( 'STDIN', fopen( 'php://stdin', 'r' )); function prompt( $msg ) { echo $msg . "\n"; ob_flush(); $in = trim( fgets( STDIN )); return $in; } $key = prompt( 'Please press a key' ); echo "You pressed $key\n"; ?> Does anyone have any ideas what I'm missing?
  18. Well I found the answer to my problem that seems to work OK. All i did was put this code at the very beginning of my decoding file: session_start(); session_unset(); session_destroy(); session_write_close(); session_start(); That clears away any sessions I had running so when I open a new one they don't conflict. I still like the idea of using a database but that's something I'll have to work on & learn. I already use some mysql databases for my site so it shouldn't be too hard to learn. Thanks for the ideas.
  19. I'm actually kind of learning as I go so I thought sessions would work for what I needed. The site is just a calculation program so I don't save any data that anyone enters into the form fields. I just didn't want people to lose their data until they closed their browser. I probably should have used cookies. The only sessions that get saved are ones I enter myself. Since I'm the only one who recalls any sessions we're not talking about saving a lot of different sessions.
  20. I guess I've got some learning to do because I don't know how to implement what you suggested. I'm surprised there's not just a simple command that would clear the session from the browser without having to close it.
  21. I don't want to delete the session file because I want the data saved for future use. I just want to be able to deactivate any live sessions from my browser so it does not conflict with a new previously saved session I might open up. Just like when i close the browser, the session is no longer active when I open the browser back up.
  22. I have a site where quite a few numbers are entered in different fields. I can recall a saved session but if I recall a second session then some of the numbers of the first session will be entered into the second session. So I have to close my browser each time before I change sessions. Is there a simple way to avoid this without permanently deleting the sessions? I tried session_destroy() but it didn't work so I must not be using it correctly. Here is the code I'm using to retrieve the stored session files: <?php session_destroy(); session_start(); $uname=$_POST['uname']; $fname=$_POST['fname']; if ($uname=="myname" && $fname=="") { echo "<BR>"; echo $date; echo "<BR>"; $direc="./SESSION"; $files=scandir($direc); $array_num= count($files); ?> <html> <body> <form name="file_log" method="post" action=""> <input name="fname" type="hidden" value="<?php echo $fname; ?>"> <select name="fname"> <?php $x=1; while ($x < $array_num) { ?> <option><?php echo $files[$x]; ?> </option> <?php $x++; } ?> </select> ---Choose session file <br><br><br><br> <input name="uname" type="hidden" value="<?php echo $uname; ?>"> <input type="submit" value="Restore Session"> </form> <?php } else { ?> <form name="login" method="post" action=""> Enter username: <input name="uname" type="text" value="<?php echo $uname; ?>"> <br> <input type="submit" value="SUBMIT"> </form> <?php } /* If a session file is chosen it restores the session & uses Javascript to take you back to the home page */ if ($uname=="myname" && $fname !="" ) { $sessionfile = fopen("./SESSION/".$fname, "r"); session_decode(fgets($sessionfile) ); fclose($sessionfile); echo " <script>"; echo "location.href='index.php'"; echo "</script> "; } ?> </body> </html>
  23. Thanks for all the help, I set the output_buffering to off and that made my home server work like my webhost server. So using output_buffering allows for poorly written code to get by? I don't get it, what's the real purpose of the setting?
  24. I found a line in my php.ini file that says "output_buffering=4096 " Is that what you're talking about? Do I just put a # in front of the line or put a 0 in place of the 4096 to turn it off or is there something else i need to do?
  25. I've solved this problem but I was just wondering if this is version specific. On my Apache server this code works fine exactly where it is in the file: $name= $_POST['name']; if ($name=="") { header("Location:index.php"); } but when I upload the page to my website it doesn't. I had to move those lines to the beginning of the file in order for the redirection to work. My server is using: PHP Version 5.3.2-1ubuntu4.7 My web host is using: PHP Version 5.4.24 I had a similar problem with sessions where the same file would work on my server but not on my website without doing some editing. The versions are very close but does this mean that the php version on my server is just more forgiving?
×
×
  • 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.