This is just a quick example of how you can deploy Zend Framework Captcha image component in a form.
To use HTML in a Zend Framework Form standard label you will first have to set the escape option in the relevant Label decorator to false. Like so:
Here´s an example combining Zend mail and Zend View for easy mail templating.
To set the selected value of a select element in a Zend Form object you need to use it's setValue method:
Here's a short script that will receive data from a form and turn it into an xml file, translating the posted key value pairs to xml nodes with textnodes.
The following code tries to open a file , creates it if it doesn't exist, clears it if it does excist (!), then writes to it and closes it again.
The first line of following php code produces an http header signifying that the content will be an xml file.
The second will simply retrieve the file or url and print out the contents.
This simple code example will open an image file and put the text specified in the GET parameter to via GD
To insert the current date / time MySQL offers the convenient NOW() function that can be used in an insert query. To use this same function inside a Zend framework db adapter insert statement you can use the following syntax:
To choose another layout file inside your controller all you need to do is invoke the layout helper like so:
To access the view instance from your homemade view helper you just need to create a setView method and view property. This will be automatically called upon instantiation, setting the view variable to point at the view instance.
The default routing setup for Zend is ':module/:controller/:action/*'
Often when using the Zend Form components it's convenient to Extend the Zend Form class. To set the action to of the form it will be necessary to access the base url helper method of the view object.
Because you don't have direct access to the view object from inside a Zend Form object, you have to do something like this:
The following script allows you to execute an sql dump file (for instance produced with mysqldump or phpmyadmin).
If you're using Zend Framework 1.8+, and created your project with the command line tool, then it's as simple as registering your database settings in your application.ini config file.
You can filter it to add your own custom body classes based on conditionals.
If you want to access the post inside the function you have to declare can refer to a global inside you function.
This is an example that adds a 'withheader' className to the body of the twentyten template based on whether an image is specified.
Add it to your theme's functions.php
Template tags related to setting / getting paths and directories:
to format a mysql datetime to your needs use something like:
Partials are handy because they allow you to dissect html code and template logic into smaller reusable bits. PartialLoops allow you to loop through objects and arrays in an efficient manner and in a seperate variable scope.
Sometimes it is neccessary to access variables and their values from the view object's scope that the partial was called from.
This can be done quite easily from the by calling the partialLoop() or partial() (or another view helper's) method from the partial template and then accessing the view object from that.
This PHP class creates thumbnails of jpeg, jpg, png or gif files. It uses GD and PHP. The thumbnails are saved to a specified location on disk after creation.
If only width or height of the thumbnail are specified, the image is scaled maintaining correct proportions. If both width and height of the thumb are specified, proportions are disregarded.
Also the 'maxLength' argument can be used to just specify the maximum length of the longest side of the thumbnail so that either width or height are scaled to the specified pixel value based on which is longest. In this case proportions are kept.
Use the following to set the necessary ini values that allow you to control time before php sessions are garbage collected
You can use Zend_db_profiler to capture and examine the sql queries or statements that Zend db adapter forms and executes. example:
To get the request parameters in a Zend framework controller action you can use:
This function will generate a random password string. With the length argument you can controll the number of characters returned.
To dynamically turn on error reporting inside a php script, even if it is disabled in the php.ini file you can use the following functions.
To register frontController plugins in the ZF (1.8 and higher) application.ini file you can use the following syntax:
To be able to set application wide constants inside the application ini file you can define a function as follows in the bootstrap class:
To change from the default view script (based on the action's name) and dynamically pick another view script to render you can use the following code:
Just add the following to layout.phtml (or the file of your layout template is in)
To disable the layout and the viewrenderer on the fly inside a controller you can use the following lines :
The default response segment your controllers action are outputting to is 'content'.
To change/set what response segment is written to inside your controller actions you can use the setResponseSegment method of the viewrenderer helper:
There' s a lot of regular expressions out there to match all possible email addresses out there. This is just an unrestrictive and extremely simple example of using PHP's preg_match function to check an email address. It will certainly resolve to true for any existing emailaddress. Perfectly sufficient for most general purposes
PHP file upload scripts, if not properly secured pose a big threat to your webserver, as they potentially allow attackers to run any shell command on it. Although it's quite simple to add an image upload script to your site, inexperienced php scripters often tend not to take the security risks to seriously. For a nice explanation of potential risks of file upload scripts have a look at this document (pdf) on php file uploads from scanit.be.
Here's a few precautions that should be taken :
- Download binaries and extract to C:\php (http://www.php.net/downloads.php)
- To make php4ts.dll / php5ts.dll available add your PHP directory, C:\php to the PATH. Read more about how to add your PHP directory to PATH in the corresponding FAQ entry (and then don't forget to restart the computer - logoff isn't enough).
- Rename php.ini-recommended to php.ini and copy to location where php can reach it - http://php.net/manual/en/configuration.file.php
- Edit php.ini :
extension_dir = C:\php\ext
and uncomment the extensions you need - for instance
session.save_path = "2;C:\tmp"
- The IIS user needs permission to read various files and directories, such as c:\php, php.ini, docroot, and the session tmp directory.
- Open IIS manager - rightclick & open the properties of your website. Under ISAPI Filters, add a new ISAPI filter. Use PHP as the filter name, and supply a path to the php4isapi.dll / php5isapi.dll.
- Under 'Home Directory' change the Execute Permissions to 'Scripts only'
- Click on the 'Configuration' button, and choose the Application Mappings tab. Click Add and set the Executable path to the appropriate ISAPI DLL. An example PHP 5 value is: C:\php\php5isapi.dll Supply .php as the extension. Leave 'Method exclusions' blank, and check the 'Script engine' checkbox. Now, click OK a few times.
- Stop IIS completely (NET STOP iisadmin)
- Start IIS again (NET START w3svc)
- With IIS 6 (2003 Server), open up the IIS Manager, go to Web Service Extensions, choose "Add a new Web service extension", enter in a name such as PHP, choose the Add button and for the value browse to either the ISAPI file (php4isapi.dll or
Alternative syntax for foreach loops in PHP:
The following to display errors regardless of the settings to do with this in the php.ini file
The 301 redirect is the most efficient and search engine friendly method for webpage redirection. If you have to change file names or move pages around, it's the safest option.
The correct way to do this redirect using php headers:
This is a very simple bridge script that enables you to direct ajax calls directly at PHP classes.
Do consider security when using this.
A very basic PHP / GD based captcha script for stopping those spammers from flooding your guestbooks, mailforms or any other online application susceptible to spam spawning web bots.
You can also download the captcha script here
Requires only PHP with GD library installation and a true type font file(.ttf) to create the image
First you make the actual captcha image generating file, and save it as (for instance) 'captcha.php':
To see an example of this script in a live site - have a look at this guestbook. Or just leave a comment below this article