Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. Google -> php session -> Search -> PHP: Session Handling Functions - Manual <click> Scroll down: <snip> Table of Contents session_cache_expire — Return current cache expire session_cache_limiter — Get and/or set the current cache limiter session_commit — Alias of session_write_close() session_decode — Decodes session data from a string session_destroy — Destroys all data registered to a session session_encode — Encodes the current session data as a string session_get_cookie_params — Get the session cookie parameters session_id — Get and/or set the current session id session_is_registered — Find out whether a global variable is registered in a session session_module_name — Get and/or set the current session module session_name — Get and/or set the current session name session_regenerate_id — Update the current session id with a newly generated one session_register — Register one or more global variables with the current session session_save_path — Get and/or set the current session save path session_set_cookie_params — Set the session cookie parameters session_set_save_handler — Sets user-level session storage functions session_start — Initialize session data session_unregister — Unregister a global variable from the current session session_unset — Free all session variables session_write_close — Write session data and end session Reading carefully, we notice some keywords: session_destroy — Destroys all data registered to a session Clicking on session_destroy gives us information on destroying a session, as well as examples in the manual and contributed by the community. I don't mean to be rude, but it sounds like you have a somewhat complicated system going. So how is it you managed to not know how to use Google?
  2. Your very first line of code is wrong as well: $expfornextlevel == 500*$user->level; Should be $expfornextlevel = 500*$user->level;
  3. No, it wouldn't. Using a database. Declare the column that is holding the post bodies as TEXT, TINYTEXT, or some other large text field type.
  4. I'd like to do something like: SELECT 'foo' AS bar From some_table But have a specific number of rows return, even though they'd all be identical. If I want 4 rows, I can attach a 'LIMIT 4' on the end of the query, but the table has to have at least 4 rows in it; what can I do if I'm not sure the table has that many rows? Thanks!
  5. Gah! Turns out webhosts with WHM on them need to have MySQL upgraded via WHM, under the Server Configuration -> Tweak Settings menu. There are then some commands that need to be run from SSH that will update MySQL, reconfigure apache, and re-build PHP.
  6. You can in a round about way. You can create a get_session_val.php script that takes a $_GET param and uses it to reference the $_SESSION value; return it as JSON. You'd access the script with the XHR (ajax) object. Although I'd have to wonder why the script doesn't just pre-load the Javascript with the session values that it needs.
  7. I'm not going to take the time to look through all that code. The first step you should take is modify your database object. Change your database functions ($db->select, etc.) so that they echo the entire query just before it's executed and echo the return value as well. If the script is inserting the proper records but producing a blank as well, then it is likely you have an error in your MySQL statements. The other possibility that comes to mind is your PHP script redirecting to the insert page using: header("Location: the/url"); exit(); In which case your $_POST values would be empty and might also cause a blank row to be inserted.
  8. I don't know how good this information is, I haven't read it. But while trying to set up LAMP the guide linked to this document for securing MySQL. http://www.securityfocus.com/infocus/1726
  9. I had created a MySQL dump file of the databases before upgrading. After upgrading I recreated the tables from the dump file. phpMyAdmin shows this: http://66.97.171.181/test/mysql4_1-5_0.jpg
  10. Before I had left for the weekend I had (possibly correctly) upgraded our MySQL server from 4.1 to 5.0. When I ran MySQL from the command line it reported version 5.0, so did a phpinfo() page. The last thing I did before leaving for the weekend was rebuild PHP with: ./configure make But I didn't do: make install When I came in today, the phpinfo() page reported version 5.0, but it could have been a cached page (I suppose). I decided to rebuild PHP: % apachectl stop % mysqladmin shutdown % cd php-dir % sh install_php.sh % make % make install % mysqld_safe --user=mysql & % apachectl start % mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 32 to server version: 4.1.21-standard phpinfo() page shows 4.1 as well. The server is a VPS and has cPanel and WHM installed. Can anyone provide a reason for this?
  11. I've never dealt with an issue like this before and have no idea what kind of search capabilities you hope to provide, but if you break them up A-D, E-F, etc. you will have to continuously adjust who goes where to keep the load fairly distributed. A good hashing function can do this for you. Let's say you want to distribute across N tables: users0, users1, ..., usersN You create a hash function: // returns an int between 0 and N inclusive based on user name function username_to_table_hash($user){ // perform magic return $hash; } Usage: $uname = clean_post_value($_POST["uname"]); $tbl = "users" . username_to_table_hash($uname); $q = mysql_query( "SELECT * FROM {$tbl} WHERE uname={$uname} LIMIT 1" ); Don't know how practical that'd be though; I got the idea from when I wrote a hash table back in college.
  12. You create string lookup tables. A simple example. <?php $en = Array(); $en["HI"] = "Hello"; $en["BYE"] = "Goodbye"; $sp = Array(); $sp["HI"] = "Hola"; $sp["BYE"] = "Adios"; // You would set the following var based on their selection from the dropdown $lang = $sp; // OR $lang = $en; echo $lang["HI"] . "<br>"; echo $lang["BYE"] . "<br>"; ?>
  13. Which operating system is this hosted on? If it's *nix: <?php $cmds = Array(); $cmds[] = "pwd"; $cmds[] = "ls -lh"; $cmds[] = "mysql -v"; $outfile = "/path/to/file/out.txt"; $redir = ">"; foreach($cmds as $cmd){ exec("echo \"{$cmd}\n\" {$redir} {$outfile}"); $redir = ">>"; exec("{$cmd} {$redir} {$outfile};echo \"\n\n\" {$redir} {$outfile}"); } ?> (EDIT) Bah! I need to read more carefully; I don't know if file redirection works in DOS.
  14. Part of programming is using the proper tool for the job. There's a lot of functionality that you will needlessly write into your PHP programs that can be handled more efficiently by the database, especially things like statistics or date / time functions. So learn both! Muahahahah
  15. Why don't you just do this: $file = '/path/to/file/file.csv'; $sql = "SELECT your_statement_here " . "INTO OUTFILE '{$file}' " . "FIELDS TERMINATED BY ',' " . "LINES TERMINATED BY '\n'"; if(mysql_query($sql)){ // Just a test echo file_get_contents($file); } (EDIT) Never tried this approach, but why do it in PHP when MySQL will do it faster!
  16. That's why you have the job_id in the drafts table. Each job has it's own id, multiple drafts can refer to the same id, thus a single project can have multiple drafts attached to it. You said the client wants to be able to select a revision as the chosen one for the draft. You can do this in two ways. The first is add a TINYINT(1) column to the revisions table; 1 indicates the revision is chosen for a draft, 0 otherwise. For all the revisions for a particular draft, only one can be value 1. The other way is to include an INT column in the drafts table, call it `selected`. It holds 0 when no revision has been chosen and the id of the corresponding image when a revision has been chosen. Each method is about the same amount of work for clearing the selected revision or changing it to a new one, although the INT column in the drafts table might equate to slightly less. Depending on the amount of space MySQL uses for TINYINT(1) compared to INT, one might equate to less disk usage given an average of N revisions per draft. I don't think I'd be overly concerned with that though.
  17. If the images are attached to the drafts, you should probably keep the drafts table. Otherwise you're likely to end up with redundant data in either the project or images because you need a way of connecting images to a draft and linking the draft to the project. The only thing I think you're missing is the draft_id column in your images table. Also, you have two columns for thumbnails, what happens when you need to include more than two thumbnails? You going to add an extra column? I wouldn't organize it in this approach. If you're dealing with multiple thumbnails, pick one of the following IMO: Set up a thumbnails table: id image_id If you name the files after the id in the thumbnails table and the mime type is always the same, thats probably all you need to store in there. You create a new row for each thumbnail of an image. The alternate method is to develop a file naming mechanism where if the main image is named 1, then the thumbnails are named 1_th1, 1_th2, 1_th3, etc. You'd then have to have a function that scanned the file system for an image's thumbnails. Personally I think the DB approach is better. But the last thing you want is to have an image table with the following columns: thumb1, thumb2, thumb3, ..., thumbN (where N ends up being some number like 10 or 20 or even higher)
  18. SA, you have seen this right: http://www.phpfreaks.com/forums/index.php/topic,147914.msg635076.html#msg635076
  19. That's right, the probability of using those other languages for web development is less than 1%. But I didn't say they should learn them to become a better PHP programmer, but instead to become a better programmer in general. C is a fairly low level language and C++ can be if you choose. A language like PHP hides a lot of the nitty gritty details; understanding some of those details will make you a better PHP programmer. For example, a PHP programmer can't figure out why their script is performing poorly. They've narrowed it down to a portion of the script that is doing repeated string concatenation. Someone who has used a more low level language will tell you the reason is probably because of repeated memory allocation / deallocation on a large chunk of memory. To be a better programmer, you really have to understand some concepts at the hardware level. You will not learn those concepts dealing with a "high-level" language like PHP. Anyways, what I made was a recommendation to become a better programmer overall. If this person wants to work with PHP only, I'd second your recommendation on reading the manual in terms of objects. Of course, you can't really appreciate the concept of objects until you create them in a language that doesn't support them, such as C.
  20. Honestly, if you want to become a better programmer I would recommend ditching PHP for a short period of time. I recommend picking up a book on C. Spend some time learning the syntax and write a few simple CLI programs; the syntax is very similar to PHP so it shouldn't be terribly difficult. You want to really understand pointers and what's happening there though. Once you've written a few simple things, pick up a book on data structures and learn how to create simple things like linked lists, queues, hash tables, binary search trees, priority queues, etc. I would then recommend picking up either C++ or Java. I'd pick C++ over Java since you have to manage your own memory allocations, like you do in C. If you're motivated and spend a bit of time each day on this, you should be back to PHP within a couple of months. Other than buying a couple of books, you can get all the software you need for compiling your programs for free. You can become a decent PHP programmer without doing any of this of course, but using a couple of older languages will give you a new perspective on PHP when you return. 1) You will understand on a lower level how a computer works and certain concepts in PHP will just fall into place. 2) You will be able to appreciate everything PHP does for you!
  21. I don't have time to look at your current setup in any detail right now, but I'll come back on my lunch break and see what I can't recommend for you. In the meantime, if you want to create a new directory it's pretty easy. // Assume $details is an array of information describing what goes // into the job table. Creating the record in the DB is not important, // it's creating the directory that we care about right now. function create_job($details){ // Sanitize incoming data, prepare your sql, and insert into the // database; assume the result from mysql_query is stored in $q if($q){ // Success, so we can create a directory $baseDir = "/home/user/public_html/drafts/"; // Now we append to the directory the id of the last inserted record $baseDir .= mysql_insert_id(); // We can't create a directory if it already exists if(!file_exists($baseDir) || !is_dir($baseDir) ){ $result = mkdir( $baseDir ); // Default permissions are 0777, specify a second // parameter if you want // At this point, we know the directory exists so we can use // move_uploaded_file to copy the file into the directory, don't forget to // rename it based on mysql_insert_id() } } }
  22. Once you start pulling in the tens of thousands and higher, no matter how optimized you make things, its always going to take a while to load in a browser. This is why you set up tables with proper indexes and use pagination where appropriate. If you're expecting to pull 10 million rows, process them, and spit them out to the user before they age a bit, you're on some pretty strong stuff.
  23. It's a shame to realize that money could have been spent on education. It's a relief to realize it doesn't take any education to create those logos.
  24. I don't think saving the files on the disk and just storing their name, and possibly path, is going to create any more programming than if you stored the files as BLOBs inside the database; this goes for both PHP and .NET. In both cases you need to detect the mime type of the file when it is uploaded and save that, so you're not losing or saving any time there. In both cases you have to gather the contents of the file and dump it back to the client, setting headers before you do. You have maybe two or three lines of extra code if the file is stored on disk because you have to fopen, fpassthru, fclose, but that's it. It doesn't even really add extra work in the case of saving revisions or file history. jobs id name drafts id job_id name draft_revisions id draft_id mime_type orig_name I'm assuming a structure where you have multiple jobs and each job has multiple drafts; as such, the jobs and drafts tables are fairly self explanatory. The interface that I imagine is one where the user selects a project and is given a list of drafts; they select a draft and are given a list of revisions for that draft; clicking on a particular revision serves that file. Let's save the uploaded files in: /home/user/public_html/drafts Let's add a subdirectory for each project created: /home/user/public_html/drafts/<project_id> We do this only because we might have to inspect the directory manually; we don't want to be bombarded with a billion files plopped into a single directory. There is probably no need to add further subdirectories unless we expect lots of revisions; in that case, I'd suggest subdirectories like so: /home/user/public_html/drafts/<project_id>/<draft_id> We store the files in public_html to make them web accessible and serving them easier; we can just provide direct paths and apache can serve the file without invoking PHP. If the files are sensitive, you will want to NOT put them in public_html, but instead place them higher in the directory structure and use a PHP script to fetch their contents (like if they had been saved as a BLOB). A couple of notes about the draft_revisions table; it looks like its missing some fields! Actually, it's not. It has everything we need right there. If the id column is an auto_incrementing primary key, it is guaranteed to be unique; thus when saving files to the file system we can use this id. When files are requested, we will know which project, draft, and revision they are seeking; since we have a predetermined path layout, this provides us with everything we need to load the file. For example, a user creates the first project in the system, calling it test. They then create a draft, named a_draft, and upload the file word.doc. They then upload a revision, calling it word2.doc. Tables +------+-------------+--------------+ | jobs | id | name | +------+-------------+--------------+ | | 1 | test | +------+-------------+--------------+ +--------+------+---------+------------+ | drafts | id | job_id | name | +--------+------+---------+------------+ | | 1 | 1 | a_draft | +--------+------+---------+------------+ +-----------------+------+-----------+------------+-----------+ | draft_revisions | id | draft_id | mime_type | orig_name | +-----------------+------+-----------+------------+-----------+ | | 1 | 1 | ms word | word.doc | +-----------------+------+-----------+------------+-----------+ | | 2 | 1 | ms word | word2.doc | +-----------------+------+-----------+------------+-----------+ Our files will be stored here: <i>word.doc</i>: /home/user/public_html/drafts/1/1 <i>word2.doc</i>: /home/user/public_html/drafts/1/2 You might be wondering how we determine which revisions are newest and which are oldest for a particular draft; you can add a DATETIME field or, since the id column is an auto_incrementing primary key, you can assume lower IDs represent older files (if you don't need the exact time it was uploaded). Some PHP: <?php function list_drafts($job){ $Clean = Array(); $Clean['Job'] = // Clean the variable $job // We want numbered output mysql_query("SET @numbering = 0"); // Get the drafts from the job $sql = "SELECT " . "id, name, @numbering := @numbering + 1 AS row " . "FROM drafts WHERE job_id={$Clean['Job']} " . "ORDER BY id"; $q = mysql_query($sql); // Now process $q } function list_revisions($draft){ $Clean = Array(); $Clean['Draft'] = // Clean the variable $draft // We want numbered output mysql_query("SET @numbering = 0"); // Get the revisions from the draft $sql = "SELECT " . "r.mime_type, r.orig_name, " . "@numbering := @numbering + 1 AS row, " . "CONCAT( 'drafts/', d.job_id, '/', r.id ) AS file " . "FROM draft_revisions r, drafts d " . "WHERE " . "d.id={$Clean['Draft']} AND " . "d.id=r.draft_id " . "ORDER BY r.id"; $q = mysql_query($sql); // Now process $q } ?>
×
×
  • 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.