tag:blogger.com,1999:blog-347625072024-02-28T21:00:10.164+05:30Php ManiaA Techincal Blog on solutions and knowledge about PHP / HTML / JavaScript / Linux / AJAX.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.comBlogger62125tag:blogger.com,1999:blog-34762507.post-52964769321638229502014-12-12T16:53:00.002+05:302014-12-12T16:53:50.171+05:30What is htaccess?<div dir="ltr" style="text-align: left;" trbidi="on">
<style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
</style>
<br />
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Using
this ".htaccess" file we can control "php.ini"
and "httpd.conf" file.</span></span></div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">For
php.ini:</span></span></div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">for
register globals Enter "php_flag register_globals on" in
that file and place it inside the context folder where you are
running the php files. Now this is set to globals throughout the
files present inside that context folder. This is boolean so we are
giving like "php_flag". if it is the value we have to give
like "php_value"</span></span></div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">For
example : [php_value sendmail_from "dineshsdk85@gmail.com"]
we have to give like this for the values.</span></span></div>
</div>
Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-73987633168745991362014-12-12T16:48:00.002+05:302014-12-12T16:48:18.472+05:30PHP Form Hijacking. How to prevent form hijacking in PHP?<div dir="ltr" style="text-align: left;" trbidi="on">
<style type="text/css">
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
</style>
<br />
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">Following
things can be done for preventing your PHP Form from Hijacking</span></span></div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">1.
Make register_globals to off to prevent Form Injection with malicious
data.</span></span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">2.
Make Error_reporting to E_ALL so that all variables will be
initialized before using them.</span></span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">3.
Make practice of using htmlentities(), strip_tags(), utf8_decode()
and addslashes() for filtering malicious data in php</span></span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">4.
Make practice of using mysql_escape_string() in mysql.</span></span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">5.
User Input Sanitization-Never trust web user submitted data. Follow
good clieint side data validation practices with regular expressions
before submitting data to the server.</span></span></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Arial, sans-serif;"><span style="font-size: x-small;">6.
Form Submission Key Validation: A singleton method can be used to
generate a Session form key & validating form being submitted for
the same value against hidden form key params.</span></span></div>
</div>
Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-41666505348915849582012-06-21T13:20:00.001+05:302012-06-21T13:20:55.275+05:30How to increase PHPs execution time for processing large set of records?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Arial,Helvetica,sans-serif;">
1. In php.ini file change the below line values it will change the maximum execution time.<br /><br />max_execution_time 30<br /><br />2. To increase the execution time runtime we can use the ini_set() function.<br />e.g.<br />ini_set('max_execution_time' '-1'); - it sets maximum execution time to infinity.</div>
</div>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-53592523256237085872012-06-21T13:19:00.001+05:302012-06-21T13:19:14.127+05:30What is CAPTCHA?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Arial,Helvetica,sans-serif;">
<b>CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. </b><br /><br />To prevent spammers from using bots to automatically fill out forms, CAPTCHA code generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans can determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field the application can be fairly assured that there is a human client using it.</div>
</div>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-5422320785423395862012-06-21T13:16:00.002+05:302012-06-21T13:16:31.631+05:30What are the different methods to optimize the MySQL query?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Arial,Helvetica,sans-serif;">
<b>It does not depend upon single entity. In order to optimize you have to consider many things:</b><br /><br />1. Make sure table has primary key. <br /><br />2. If there is any field which is used more frequently for searching then INDEX it.<br /><br />3. Check the order of join condition.<br /><br />4. In "Select" statement "where" condition should have indexed column.<br /><br />5. Use "Limit" clause to fetch required amount of records from the database.<br /><br />6. Use "count()" instead of "*" if you want to know the number of records fetched from the DB.</div>
</div>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-52360685840968842322012-06-21T13:11:00.001+05:302012-06-21T13:11:37.545+05:30How to prevent form Hijacking in PHP?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Arial,Helvetica,sans-serif;">
<b>Following the below steps can help prevent your PHP Form from getting Hijacked:</b><br /><br />1. Make "register_globals" set to "Off" to prevent Form Injection with malicious data.<br /><br />2. Make "Error_reporting" set to "E_ALL" so that all variables will be initialized before being used.<br /><br />3. Make practice of using htmlentities(), strip_tags() and addslashes() to filter out malicious data entered.<br /><br />4. Make practice of using mysql_escape_string() in mysql.<br /><br />5. User Input Sanitization: Never trust web user submitted data. Follow good client side data validation practices with regular expressions before submitting data to the server.</div>
</div>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-27040525241170885552012-06-21T13:04:00.001+05:302012-06-21T13:06:52.652+05:30Store Image in MySQL<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: Arial,Helvetica,sans-serif;">
</div>
<div style="font-family: Arial,Helvetica,sans-serif;">
We can use the "blob" datatype for storing the the image into the table.<br />
<br />
However, the best way to store images into MySQL is to store the location of the image as a character string.</div>
</div>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-54984940723996403202011-02-11T12:47:00.000+05:302011-02-11T12:49:09.404+05:30About ExpressionEngine [EE]Expression Engine is a very powerful content management system that can be used to manage your website and blog. All you have to do is add EE tags into the portions of your pages where you want your posts / content to appear. It has all the inbuilt basic features that is required to create a website. However, for more complex implementation you would need to buy / get free add-ons or hack the code to suit your needs.<br /><br />Fetching and displaying the data is an easy part. Challenge comes in when you want to display it in a more creative way.<br /><br />Like at one such instance, we needed a feature to add ratings for an article and at the same time add customer's review. To achieve this we simply made changes to the add-on's class file, added a field to the ratings table in the database to store the reviews as well as the score, since we wanted to display the customers review for the article along with the rating. <br /><br />Second, displaying breadcrumbs in a customized way. Though there are add-ons available for the same, but add-on's displayed the breadcrumbs based on the query string. So, we had to modify the class file to suit our requirements.<br /><br />Third, in certain cases there were limitations to using EE tags, particularly nested "weblog" tags. To overcome such situations we have used queries instead to fetch the required data for further processing in the inner loops.<br /><br /><br /><span style="font-weight:bold;">Conclusion</span><br /><br />So, unlike learning any new application especially content management systems, learning EE was comparatively less painful. The more you work on it, the more you discover about its potential. Be it a usual CMS site, Shopping Carts, Blogs etc. EESunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-31889770420384949192011-02-11T12:39:00.000+05:302011-02-11T13:04:19.346+05:30How to get next auto increment value of a primary key field in MySql?<?php<br />function mysql_next_id($table) {<br /> $result = mysql_query('SHOW TABLE STATUS LIKE "'.$table.'"');<br /> $rows = mysql_fetch_assoc($result);<br /> return $rows['auto_increment'];<br />}<br />?><br /><br />Programmers try other ways to retrieve the next auto-generated id and fail to get correct value.<br /><br />Example:<br />Most of the programmers try to get the MAX(id)+1 (or sort the table in decending order and get the first id) but this will not to work when you delete the last record.<br /><br />There is a possibility that other users have entered record in the meantime, in this case the value that you have retrieved would be incorrect. You may use LOCK TABLES to prevent such a case.<br /><br />However, the best thing is to avoid such logics.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-46690410955317479372009-11-18T20:45:00.003+05:302009-11-18T20:45:46.888+05:30What are the various methods to pass data from one web page to another web page ?Below are the ways to pass data acros the pages:<br /><br />1.POST<br />2.GET<br />3.SESSION<br />4.COOKIES<br />5.QUERY STRINGSunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-83334232442423135712009-11-18T20:45:00.001+05:302009-11-18T20:45:29.261+05:30What is a Zend Engine?The Zend Engine is an open source scripting engine (a Virtual Machine), commonly known for the important role it plays in the web automation language PHP.<br /><br />The current version of the virtual machine is The Zend Engine II and is at the heart of PHP 5.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-39275937703217995442009-11-18T20:44:00.004+05:302009-11-18T20:45:12.076+05:30What are the types of Storage Engines MySQL supports?MySQL supports several storage engines that act as handlers for different table types. MySQL storage engines include both those that handle transaction-safe tables and those that handle nontransaction-safe tables.<br /><br />To determine which storage engines your server supports by using the SHOW ENGINES statement. The value in the Support column indicates whether an engine can be used. A value of YES, NO, or DEFAULT indicates that an engine is available, not available, or avaiable and current set as the default storage engine.<br /><br />MySQL 5.1 supported storage engines<br /><br />1. MyISAM ? The default MySQL storage engine and the one that is used the most in Web, data warehousing, and other application environments. MyISAM is supported in all MySQL configurations, and is the default storage engine unless you have configured MySQL to use a different one by default.<br /><br />2. InnoDB ? A transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data. InnoDB row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent nonlocking reads increase multi-user concurrency and performance. InnoDB stores user data in clustered indexes to reduce I/O for common queries based on primary keys. To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints.<br /><br />3. Memory ? Stores all data in RAM for extremely fast access in environments that require quick lookups of reference and other like data. This engine was formerly known as the HEAP engine.<br /> <br />4. Merge ? Allows a MySQL DBA or developer to logically group a series of identical MyISAM tables and reference them as one object. Good for VLDB environments such as data warehousing.<br /> <br />5. Archive ? Provides the perfect solution for storing and retrieving large amounts of seldom-referenced historical, archived, or security audit information.<br /><br />6. Federated ? Offers the ability to link separate MySQL servers to create one logical database from many physical servers. Very good for distributed or data mart environments.<br /> <br />7. NDBCLUSTER (also known as NDB) ? This clustered database engine is particularly suited for applications that require the highest possible degree of uptime and availability.<br /><br />8. CSV ? The CSV storage engine stores data in text files using comma-separated values format. You can use the CSV engine to easily exchange data between other software and applications that can import and export in CSV format.<br /> <br />9. Blackhole ? The Blackhole storage engine accepts but does not store data and retrievals always return an empty set. The functionality can be used in distributed database design where data is automatically replicated, but not stored locally.<br /> <br />10. Example ? The Example storage engine is ?stub? engine that does nothing. You can create tables with this engine, but no data can be stored in them or retrieved from them. The purpose of this engine is to serve as an example in the MySQL source code that illustrates how to begin writing new storage engines. As such, it is primarily of interest to developers.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-72332542873844369982009-11-18T20:44:00.003+05:302009-11-18T20:44:51.328+05:30What type of inheritance that php supports?PHP support the Multilevel inheritance Not a multiple inheritance.<br /><br /> For Example:<br /><br />class A{<br /><br />function hello();<br />}<br /><br />// This is possible.<br />class B extends A{<br /><br />function helloB();<br />}<br /><br />// This is not possible, IT gives the fatal error.<br />class C extends A{<br /><br />function helloC();<br />}Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-4818111760151873772009-11-18T20:44:00.001+05:302009-11-18T20:44:32.189+05:30Where Is Session Data Stored?Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.<br />The most significant differences between the two are that cookies are stored on the client, while the session data is stored on the server. As a result, sessions are more secure than cookies (no information is being sent back and forth between the client and the server) and sessions work even when the user has disabled cookies in their browser. Cookies, on the other hand, can be used to track information even from one session to another by setting it's time( ) parameter<br /><br />The session.save_path setting specifies the directory name for session data.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-84379653922674153412009-11-18T20:43:00.006+05:302009-11-18T20:44:16.614+05:30What is the purpose of ob_start() ?This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.<br /><br />The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents. <br /><br />Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-56259978308620871452009-11-18T20:43:00.005+05:302009-11-18T20:43:55.874+05:30What are new features that are in added in PHP5?Following are new features added in PHP5<br /><br />1. PHP 5 introduces the Standard PHP Library (SPL) which provides a number of ready-made classes and interfaces.<br />2. Access Modifiers are added in PHP5<br />3. PHP5 has built-in exception classes that makes it very easy to create your own customized exceptions through inheritance.<br />4. PHP 5 introduces the mysqli (MySQL Improved) extension with support for the features of MySQL databases versions 4.1 and higher. So use of prepare statements are allowed<br />5. PHP5 comes with PDO which is a common interface for different database systems is only made possible by the new object model.<br />6. SQLite is a database engine incorporated in php5 which can be used to develope faster leaner and more versatile applications.<br />7. In PHP 5 all Extensible Markup Language (XML) support is provided by the libxml2 XML toolkit.<br />8. The reflection classes included in PHP 5 provide ways to introspect objects and reverse engineer code.<br />9. In addition to built-in classes PHP 5 also offers built-in interfaces. Iterator is the most important as a number of classes and interfaces are derived from this interface.<br />10. PHP 5 introduces a number of new "magic" methods. Magic methods begin with a double underscore and this requires changing any user-defined methods or functions that use this naming convention.<br />11. The major change to PHP in version 5 relating to OOP is usually summed up by saying that objects are now passed by reference.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-22854425722991616122009-11-18T20:43:00.003+05:302009-11-18T20:43:38.942+05:30What is the difference between session_register() and $_SESSION?Following are differences between session_register and $_SESSION<br /><br />1. session_register function returns boolean value, whereas $_SESSION returns string value.<br /><br />2. session_register function does'nt work if register_global is disabled. $_SESSION works in both case whether register_global is disabled or enabled. <br />So using $_SESSION for session variable manipulation is more appropriate.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-46753985805818217252009-11-18T20:43:00.001+05:302009-11-18T20:43:22.719+05:30Which will execute faster POST or GET? ExplainPOST is most secure so it have to pass some process. GET is simple way to send via URL so it is will be fast.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-77892577253822773822009-11-18T20:42:00.001+05:302009-11-18T20:42:56.597+05:30What is the difference between echo and print statement?Both echo and print are language constructs.<br /><br />However print() acts like a function in that it returns a value and can be used in complex expressions.<br /><br />Furthermore echo without parentheses can take multiple arguments. Echo with parentheses and print can only take a single argument.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-86418289225567497362009-11-18T20:41:00.000+05:302009-11-18T20:42:09.032+05:30How to upload the file from one server to Remote server?$fileToBeUploaded = "filename.txt";<br /><br />$source = fopen($fileToBeUploaded,"r");<br />$conn = ftp_connect("ftp.myserver.com");<br />ftp_login($conn,"<ftp_username>","<ftp_password>");<br /><br />ftp_fput($conn,"/path_to_folder_on_remote_server/newfile.txt",$source,FTP_ASCII);<br /><br />ftp_close($conn);Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-12944125836696037482009-10-21T21:12:00.000+05:302009-10-21T21:14:17.868+05:30Code for "Bookmark Us" in JavascriptPlace the following script into your <head>section in the page you need to use it:<br /><br /><script type="text/javascript"><br /><br />function bookmark_us(url, title){<br /><br />if (window.sidebar) // firefox<br /> window.sidebar.addPanel(title, url, "");<br />else if(window.opera && window.print){ // opera<br /> var elem = document.createElement('a');<br /> elem.setAttribute('href',url);<br /> elem.setAttribute('title',title);<br /> elem.setAttribute('rel','sidebar');<br /> elem.click();<br />}<br />else if(document.all)// ie<br /> window.external.AddFavorite(url, title);<br />}<br /></script><br /><br />Next, place the following code in order to show the link that opens browser's bookmark window:<br /><br /><a href="javascript:bookmark_us('http://phpcoders.blogspot.com/','Php Coders')">Bookmark us!</a><br /><br />That is all! You have now a full working bookmark us script.Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-55022204262679535642009-10-21T21:08:00.000+05:302009-10-21T21:09:19.177+05:30JavaScript Wait While Loading Page Display ImageIf you have a page that takes long time to display it is a good idea to display a "wait until the page loads" image. This tutorial show you how to implement this in your webpage.<br /><br /><span style="font-weight:bold;">Below are the steps to implement the feature:</span><br /><br />Step 1. Every time your page loads a "init()" function will load.<br /><br /><body onLoad="init()"><br /><br />Step 2. Define a div named "loading" right after <body> section.<br /><br /><div id="loading" style="position:absolute; width:100%; text-align:center; top:300px;"><br /><img src="loading.gif" border=0></div><br /><br />The loading.gif image should be an animated gif that suggests that the page is still loading.<br /><br />Step 3. Place this javascript code right after you define the div.<br /><br /> <script><br /> var ld=(document.all);<br /> var ns4=document.layers;<br /> var ns6=document.getElementById&&!document.all;<br /> var ie4=document.all;<br /> if (ns4)<br /> ld=document.loading;<br /> else if (ns6)<br /> ld=document.getElementById("loading").style;<br /> else if (ie4)<br /> ld=document.all.loading.style;<br /> function init()<br /> {<br /> if(ns4){ld.visibility="hidden";}<br /> else if (ns6||ie4) ld.display="none";<br /> }<br /> </script>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-50885488098502153482009-10-21T21:00:00.000+05:302009-10-21T21:05:11.740+05:30How to diable Right Click in JavaScript?Neat code to restrict a user to right click and view the code or save an image. Though, it does not assure complete safety for your source (there is always a way to copy them), but it is better than nothing.<br /><br />Copy & Paste this script under the HEAD in the HTML area of your webpage.<br /><br /><script><br />var isNS = (navigator.appName == "Netscape") ? 1 : 0;<br />if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);<br />function mischandler(){<br /> return false;<br />}<br />function mousehandler(e){<br /> var myevent = (isNS) ? e : event;<br /> var eventbutton = (isNS) ? myevent.which : myevent.button;<br /> if((eventbutton==2)||(eventbutton==3)) return false;<br />}<br />document.oncontextmenu = mischandler;<br />document.onmousedown = mousehandler;<br />document.onmouseup = mousehandler;<br /></script>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-36659358269271599722009-08-18T15:26:00.001+05:302009-08-18T15:26:44.948+05:30How to force open a window that asks to "Open" or "Save As" the file?Below is the working example of a code that would ask the user to "Open" or "Save" the file.<br /><br />Note: There should not be any output displayed above the below mentioned code i.e. the rules for "headers" in php applies here.<br /><br /><?<br />$contentFilePath = "/docs/xyz.pdf"; // Specify the path to the file that needs to be downloaded. This could also be a file that is generated dynamically.<br /> <br />if ($fd = fopen ($contentFilePath, "rb")) {<br /> $fsize = filesize($contentFilePath);<br /> $fname = basename ($contentFilePath);<br /> <br /> // Specify the required headers<br /> header("Pragma: ");<br /> header("Cache-Control: ");<br /> header("Content-type: application/octet-stream");<br /> header("Content-Disposition: attachment; filename=\"".$fname."\"");<br /> header("Content-length: $fsize");<br /> <br /> fpassthru($fd);<br />}<br />?>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0tag:blogger.com,1999:blog-34762507.post-5929591546528484532009-08-18T15:25:00.001+05:302009-08-18T15:25:59.003+05:30Generate random alphanumeric password in PhpA simple function which returns an autogenerated random alphanumerical password with the specified length.<br /> <br /><br />Code:<br /><br /><?<br />function NewPassword($len = 8)<br />{<br /> $chars=array(<br /> "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",<br /> "Q","R","S","T","U","V","W","X","Y","Z", //upper-case<br /> "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",<br /> "q","r","s","t","u","v","w","x","y","z", //lower-case<br /> "0","1","2","3","4","5","6","7","8","9" //numbers<br /> );<br /><br /> srand((float) microtime() * 10000000);<br /> $array=array_rand($chars, $len);<br /><br /> $password="";<br /> foreach ($array as $key => $val)<br /> $password.=$chars[$val];<br /><br /> return $password;<br />}<br />?>Sunny Jangirahttp://www.blogger.com/profile/03644086757372279849noreply@blogger.com0