Skip to main content

Posts

Showing posts with the label language-php

Javascript and HTML: Async Communication Prototype

In this article I go over an asynchronous communication prototype I had made in straight Javascript that you use to POST to a server script and pass along the response to a Javascript function specified by the initial call to the prototype. The main benefit here is that you don’t need a full page refresh, which is great for implementing web interfaces that have an application feel to them. It doesn’t use any bulky libraries and should work on all browsers. An ideal use case for this would be websites hosted in an internal network that you wanted to act like an application. Though, with extensive modification you could add security features or just run it through https with proper verification code in the PHP script. The example code is located on GitHub. In my example I have four files: example.html = the html page that gives the user two buttons that fire off asynchronous calls to a server side script. AsyncManager.js = The prototype (aka. class) that handles communication and respons...

Execute a console command in PHP revised

While it seems like there are multitude of different methods to execute commands in PHP, so far the code I will go over below is my preferred method. Using the passthru() function works nicely and includes the final return code of whatever was being executed, which is generally useful to me in error checking. In processing, I also include ob_start(), ob_get_contents(), and ob_end_clean() so that I can capture the console programs output and return it the user eventually. // Execute a console command and return both the // command's success value and any output to the console it made function executeConsoleCommand($commandToExecute, &$commandConsoleOutputToAppend) { $returnValue = 0;      // Append command to output $commandConsoleOutputToAppend .= $commandToExecute . "\r\n"; // Catch console output ob_start(); // Execute the console program passthru($commandToExecute, $returnValue); // Save console output to a string variable (this s...

.NET Path.Combine() in PHP

I’m the type of person who prefers to do things in a way that I perceive as the proper or correct way. While this tends to make things take a bit longer to accomplish, I feel the result ends up being better overall. One such thing I noticed is that file and path handling in PHP was missing a function I used quite a bit when writing C# code. In C# there is a Path.Combine() function that appends two file paths together to form one complete path without having to care what the beginning character and ending character of the two paths are. I wrote up a little function in PHP to mimic what happens. // Take a path and/or a filename and combine them into one file path function filePathCombine($path1, $path2) { $completedPath = ''; // Check if path1 ends with DIRECTORY_SEPARATOR if (substr($path1, -1) !== DIRECTORY_SEPARATOR) { $completedPath = $path1 . DIRECTORY_SEPARATOR; } else { $completedPath = $path1; } // Check if path2 starts with D...

Securing a WordPress Blog

Please view this newer article for another method of securing the wp-admin directory from access. Here are a few tips to securing a wordpress based blog or site: Change the location of your wp-content directory. This is good for making your site’s source code less discernable as a wordpress blog. In the wp-config.php file: define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content'); define('WP_CONTENT_URL', 'http://example/wp-content'); Change “wp-content” to something else. Keep in mind that some plugins are not programmed correctly and have hard-coded links to the content directory as “wp-content”, so that could cause issues. If you notice your plugins not working, open the related source files and search for the phrase. ————————– Change the admin’s login name to something besides “admin” This can be done with something like phpMyAdmin to edit the database. The user_login varchar(60) field in the wp_users table is the value you wan...

Clean URLs in PHP Yii Framework

Here is a quick tip to save some trouble. The goal here is to get clean urls like http://localhost/site/test/5 or http://localhost/site/contact without having a query string variable and also not having the filename index.php show up. My configuration: EasyPHP (apache/php/mysql combo for windows) Yii PHP framework In the Yii main.php configuration file you need: 'urlManager'=&gt;array( 'urlFormat'=&gt;'path', 'showScriptName'=&gt;false,), Inside the ‘components’ array area. In the primary directory where the index.php file is you need a .htaccess files with this in it: Options +FollowSymLinks IndexIgnore */* RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] If you have problems, check your httpd.conf file for these items: <directory c:\easyphp\www> Inside that directory section, make sure the rules don’t disallow the removal of index.php or the other rewrite rule...

EasyPHP, Wordpress, and Permalinks

I’m creating a website as a favor to a friend. To save effort, I’m just doing the development on my Windows computer. While doing that, I ran into a little issue with permalinks that seems to be unique to how EasyPHP is configured. While I won’t go into much detail on the subject, I re-affirmed the fact that WordPress is as close to as ideas as one can get when wanting to setup a basic website. I tried out probably 10 open source CMS systems and found them too complex (the admin back-ends) or too buggy to be used. Keep in mind that the website I am setting up requires only basic functionality (informational pages, a image gallery, good admin, stable code), which is what I am basing my opinion off of. What brings me to my post today is that I used EasyPHP  (a simple Apache, MySql installer and admin) to act as the local web server for testing. I was having issues with getting permalinks working. There was one gotcha that doesn’t apply to other webserver installers. What I did t...

PHP, IIS, and NetBeans

It’s been while since I have used the language, so I thought it would be fun to try making a few new ideas with it. I did a quick search to see what PHP IDEs were available.  I’ve used Eclipse quite a lot, but I’m not particularly fond of it, so I wanted to try something else. I plan on giving NetBeans a chance to see how it fairs. http://www.netbeans.org/features/php/ Seeing as I am currently using Vista Ultimate 64-bit, I decided to just use IIS. I had a few quips getting it working. I had modified IIS beforehand when I was doing some old VbScript coding, so needless to say when I tried installing PHP it didn’t work out of the box. In the IIS configuration program (use the start button search in vista on “InetMgr”): Install PHP as a ISAPI filter. In your selected application pool advances settings, make sure that “Managed Pipeline Mode” is set to “Classic” mode. In the list of global settings: Add a default document “index.php” In ISAPI Filters, add a new filter that points to (...

Is object orientated PHP scripting worth the effort?

I’m currently creating a movie review website in PHP an SQLite. I’m taking a very object orientated approach. For example, all database access goes through an object. Adding a review is as simple as calling a function with the proper data. Here is the function header: addReview($assocArrayReviewData, $assocArrayReviewBlockData) Each parameter is an associative array that corresponds to fields in the database. While I don’t want to get into too much detail, the second variable is actually an array of arrays, where each one holds a block of review information (eg: “What the box says”, “funny quotes”, “My thoughts”). The best thing about is is that once I create the administration interface I can just call that one function with the correct parameters and bam, a new review. The class also has a built-in search function (that could be used on the internal or external site). My next class that I created for primarily for the administration area. It’s an html tag class object. You might...

CMS/site project status

1149 lines of code so far. That’s not including and database file initialization code or other things such as the css for the public site. Completed (“somewhat tested”): Add/edit main page links Add/edit/delete main page basic html content blocks Visual template system and the final visual look of the site. Public index.php looks “done” visually. The main links work and display all basic – content blocks when clicked (ordered by ‘zorder’). It’s just lacking sub links (articles and galleries). To Be Completed: Delete main page links (I haven’t decided if I want it to do a recursive deletion of all content associated with it or not). Add/edit/delete articles (aka. multipage basic html content blocks). Add/edit/delete image galleries. Make the admin pages secure. Testing, testing, and more testing! I’ve been thinking of not bothering with an image gallery aspect. The multi page articles would have similar abilities to a photo gallery. The only difference is that it could not support ...

Accessing page content from the front and back-end of a site

As I’m programming this database driven website, I’ve come into a few irritating little issues. Today I’ll talk about a few methods to access page content (images) from the back-end. I’ve created a way to create and edit page content with a browser based WYSIWYG editor. The problem is after the first time the data is submitted to the server, all images are set with a path that now only works from the root directory of the website. So when a user tries to edit some page content with images in the WYSIWYG editor they see broken images (aka. “The dreaded Red X”). I thought of a few ways to fix the problem. I’ll also mention which method I actually used in the end. 1. Have the PHP script handle the path conversions. This would mean two functions or so with a few replacements using regular expressions. So when the fetched data is sent to the user all of the html image tags are modified. When or if the user sends the data back they are remodified (excluding any new images the user is...

Finally got moving on something...

From the previous posts it’s easy to notice that I’ve been searching for an efficient way to code large web projects. While I am still open to frameworks and such, I had something happen that kind of “brought me back to my roots.” I have the job of making a website for a not-for-profit organization in my area. I decided that they should have something easy to update, so that means a data driven site with a back-end. I don’t want to use premade systems because they have too many things I don’t want included. I therefore decided to go with what I’ve worked with in the past which is straight PHP. More specifically PHP5+ and the SQLite database engine. PHP5 perfects a good deal of useful features over the older versions such as the class/object model. It also adds support built-in for the file based SQLite engine. For what I am creating, SQLite takes out a lot of the unnecessary complexity of using MySQL. I’ve got the database and gene...

Getting a Symfony development enviroment running on windows

Nothing is ever easy… Anyways, to get a computer ready to start developing with the Symfony PHP framework you have a few options. You can take the long, long route and install apache, php, and a database server. With that you have to do a good deal of configuration to get everything working together. You could also download WAMP or XAMPP, which are just prepackaged versions. I haven’t used XAMPP, so I can’t say how you would get that working. The best reason for using WAMP is that it is self contained in c:\wamp folder by default. You can also start and stop all of the server processes (Apache & MySQL) anytime by just closing the tray icon. It’s great so you don’t have unnecessary processes running all of the time. The main problem is that WAMP and Symfony don’t work “out of the box.” No surprise there. This is the process I used to get WAMP working with Symfony: Download WAMP (1.6.6) and install: http://www.wampserver.com/en/ Open a browser to http://localhost/ WAMP should...

A bit disappointed so far...

I started playing around with Visual Web Developer Express 2005 (VWD). I had originally planned on using VWD with MySQL. The problem is that to use the new stuff in ASP.NET 2.0 like the pre-made authentication you have to use Microsoft’s own SQL server, or try to get some convoluted method of making MySQL work as the provider. I’m sure that I could eventually get it working, but in the end it would not provide me the free easy to use fast development solution I was looking for in asp.net and MySQL. I had a plan to develop a dynamic small business website with user authentication, but I see now that it probably won’t be with VWD Express and MySQL. If I have to reinvent the wheel for everything I’d rather just use PHP and MySQL. That being said, I still plan on messing around with VWD and Microsoft’s SQL Express. I might be doing some research about Ruby On Rails to see if that would better meet my needs.