Jump to content

etrader

Members
  • Posts

    315
  • Joined

  • Last visited

    Never

Everything posted by etrader

  1. I use a simple php code (taken from php.net example) to resize an image list($width, $height) = getimagesize($filename); $new_height = $height / $width * 400; $image_p = imagecreatetruecolor(400, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, 400, $new_height, $width, $height); imagejpeg($image_p, "new.jpg"); Here, we create a blank image and merge it with the resized image. I wonder if it is the simplest way to resize and save an image. Is it really necessary to create a blank background image?
  2. I have a normalized database in the form of ID user_id key value 1 3 first_name Brian 2 3 last_name Tardy 3 4 first_name John 4 4 last_name Wilson What is the fastest way to capture these values within php? I want to perform a SELECT to catch the values for every user as $result=mysql_query("SELECT * FROM users_data WHERE user_id = '$id'"); while($row=mysql_fetch_array($result)) { here we process all data for a given user and write it to text file as a single line } Since it is a long list (100K users with about 10M of rows in user_data), I am looking for the fastest and most reliable way to scan all the database. ?>
  3. I've read lots of articles and discussions about security issues for using session for user authentication; but I did not come to an explicit conclusion which is the best method. I decide to generate two session parameters (1) ID (2) a randomly generated Access Token which is stored in the database. I want to add more security: 1. Where to store session? server-side or client-side by session session.use_only_cookies ? 2. Is it good to check IP and User Agent before authentication by session? In this case I will lose the option of Remember Me as IP can be changed. 3. Which of the session parameters of http://php.net/manual/en/session.configuration.php is more practical to have a good security? Any additional idea?
  4. I want to make a local version of some variable taken from database to reduce the number of mysql queries. For example, creating a local menu as an array in php file instead of making a query every time to take list of menu from mysql database.
  5. I produce a series of php variables in a php strict (mostly come from mysql), and I want to save them as a php file. To be use for "include". What is the safest way to write them in a php file? I tried to save them in the manner of saving a text file with fwrite as $data='<?php $cat=array('array created in the text'); $string='some value';?>'; $fh = fopen("file.php", 'w'); fwrite($fh, $data); Now, file.php is a normal php file and I can call it with "include"; but the problem is that this method is not safe. For example, if the string is "There's something", php gives error for the presence of ' in the string. I can skip ' and " by backslash; but this method is costy, as I need to perform this process for all strings to be saved. Moreover, there might be other source of errors too (that I have not encountered yet). Is there a safe way for writing a php code to file?
  6. Thanks a million! It did lead me on the right direction. P.S. The wonderful quotation in your signature made my day I wish the best for your Roboroster project
  7. I have a mysql table with the structure of ID Menu_Name Parent_ID 1 Finance NULL 2 Business NULL 3 Investment 1 4 Trading 2 How can I create a html <ul><li> list based on the parent?
  8. No I meant the database system, db3, db4, gdbm, etc for configuring php. I have not installed dba yet. I want to know how to install php-dba by yum with BerkeleyDB
  9. All instructions for enabling php-dba is via fresh installation of php with --enable-dba=shared .... When php has been installed, one can install dba later by yum install php-dba. In this method there is no place to define the location of each database dir, as we need to enable some of them due to possible conflicts. How to install php-dba via yum?
  10. Is there something like str_pad to make a string with a fixed width on the bases of bytes (not characters). If not, is it possible to safely convert characters to bytes to have a fixed width (of bytes). As a matter of fact, I want to use the strings (to be written to a file) as offsets for reading lines with fseek. Thanks
  11. When I try to install dBase by yum install dbase, it says Package php-dbase is obsoleted by php-common, trying to install php-common-5.1.6-27.el5_5.3.i386 instead Package matching php-common-5.1.6.27.el5_5.3.i386 already installed. Checking for update. Nothing to do
  12. I have want to install dBase on my servers (CentOS and Ubuntu), but the problem is that PHP 5.3.6 has been installed by yum as php53. dBase is available in repositories as php-dbase, and this will have conflict with php-common. Alternatively, I tried to compile it from source, but after downloading php 5.3.8 (the latest version), I just found that dbase does not exist in ext folder. How can I enable dBase on php 5.3.6?
  13. I want to load and display the content of a text file (actually it is a cache file). I tested both method using a long for loop as for ($i=0; $i < 10000; $i++) { $handle = fopen("test.txt", "r"); $text = fread($handle, filesize("test.txt")); fclose($handle); echo $text; } and for ($i=0; $i < 10000; $i++) { $text = file_get_contents("test.txt"); echo $text; } but the results were similar, though with a large distribution of the comparative data. The speed of a method was 0.5 to 2.0 faster than the other one (in various runs). Which method do you recommend? Could you please quote the pros and cons of each method?
  14. I have a large number of files. It is recommended to save the files with hashing system to have fast access to files through the OS. But I have no practical knowledge about hash. Could you please give me a hint, how to save a file with hash coded system via php? and how to read the hash coded filename by php? Thank you in advance!
  15. I want to parse some tiny lines from a webpage. I have few questions: 1. What is faster and better: cURL or file_get_contents? 2. Is it better to run preg_match commands form every line I want OR first get a shorter part (e.g. between <head> tag) then running preg_match for the lines? 3. Actually, I need to load the whole page before parsing. Is there a way to stop loading the whole page. For example, when I want something between <head> tag; stop loading <body>? Thank you in advance!
  16. Thanks but you did not get my problem. I get language by $_GET; but how to load corresponding language file. $language = $_GET['lang']; Now I need something like this within the function include("$language.php"); My problem is how to run the function for each language (e.g. 50 languages).
  17. I have a function to read terms from an array stored in language file as function _language($term) { include('fr.php'); if(!empty($lang[$term])) { $lterm=$lang[$term]; } else { $lterm = $term;} return $lterm; } The problem is that I get the language code from url as ?lang=en or ?lang=fr; but I cannot bring this string into the function. How I can tell the function to read appropriate language file (fr.php or en.php or es.php) upon choosing language in ?lang=XX
  18. Here, it is function duration($amount){ $h = $amount / 3600 ; $h = floor($h) ; $min = $h * 3600 ; $min = $amount - $min ; $min = $min / 60 ; $min = floor($min) ; $sec = ($min * 60) + ($h * 3600); $sec = $amount - $sec ; $return = "$h:$min:$sec" ; return $return ; } $second = 7291 ; $time = duration($second) ; echo $time ;
  19. Thanks for the idea, funstein I wrote a function to consider hour too. Thank you all fellas
  20. Other than if statement, is there a way to change a duration give in seconds (e.g. 5746 seconds) to the standard format of x hours and y minutes and z seconds?
  21. One time the page is load when submitting the form. Is it possible to avoid this page load by a method other than <form> to set the cookie? Or I need to use AJAX to set the cookie without page load?
  22. I want to update a value by setting cookie. I use this code: <?php if (isset($_POST['ChangeOrdering'])) { setcookie("Ordering", $_POST['ChangeOrdering'], time() + 31536000); } echo $_COOKIE["Ordering"]; ?> <form method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>"> Reorder messages: <select name="ChangeOrdering"> <option value="DateAdded ASC">Oldest first</option> <option value="DateAdded DESC">Newest first</option> <option value="Title ASC">By Title, A-Z</option> <option value="Title DESC">By Title, Z-A</option> </select> <input type="submit" value=" Save Settings " /> </form> Problem is that echo will return the previous cookie set, not the last value. As a matter of fact, my problem is about updating the cookie. It seems that the browser load the cookie before it is updated by the POST value.
  23. I use foreach to echo a list of tags come out of an array as foreach ($array as $tag) { echo "$tag,"; } This produces "tag1,tag2,tag3,". The problem is the last ",". How to tell the foreach loop to avoid including "," after the last sequence?
  24. But array-combine creates an array by using one array for keys and another for its values. Not both values are inside the foreach loop to be used for echo or other processing.
×
×
  • 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.