Tuesday, December 15, 2009
Updated Project: New Artist Schedules
Our site allgoodseats.com has been updated with our users in mind. we want to give instant access to the top artists that are playing currently while still allowing easy access to all other artists. The popular artists and their full tour schedules can be found at allgoodseats.com/concert-tickets.html. The artist schedules are updated daily so any new dates added will not be missed and you can view more information about any tour date by followoing the link for that event.
Friday, December 4, 2009
Project Finally Finished
After many weeks of writing code and debugging our new project is finally launched: Fans in the Stands. This site is all about the artists. You can view their biography, discography and tour dates. Each artist has their own page all about them with up to date tour schedule. Each tour date has its own event page with more information.
Lots of functionality in this site and the potential to add lots more. User accounts will probably be added in the future where fans can favorite artists and receive live updates of those artist's tours or be notified of artists coming near their city. If you have any ideas or criticisms please respond.
Lots of functionality in this site and the potential to add lots more. User accounts will probably be added in the future where fans can favorite artists and receive live updates of those artist's tours or be notified of artists coming near their city. If you have any ideas or criticisms please respond.
Sunday, November 29, 2009
Simple Header Reader
Well I tried doing a search on this myself but after many unsuccessful searches I decided to tackle the task myself (I really thought I would find something quickly). I figured it would be simple so someone must have done something on the topic before and I proved myself wrong - well about the finding part, it was rather simple.
Anyway what this little function does is read only the headers of a page using PhP's curl() functions and returns them as an associative array. A great way to check if you need to update an RSS cache or something similar.
The HTTP header index will simply be 'HTTP' every other header will be in the form <header> => <value>.
example:
enjoy :)
Anyway what this little function does is read only the headers of a page using PhP's curl() functions and returns them as an associative array. A great way to check if you need to update an RSS cache or something similar.
function checkHeaders($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$content = curl_exec($ch);
curl_close($ch);
preg_match_all('/[^:]*[\r\n]|([^:]*):(.*)[\r\n]/', $content, $matches, PREG_SET_ORDER);
foreach ( $matches as $match ) {
if ( !empty($match[0]) ) {
if( strstr($match[0], 'HTTP') === false )
$headers[$match[1]] = $match[2];
else
$headers['HTTP'] = $match[0];
}
}
return $headers;
}
The HTTP header index will simply be 'HTTP' every other header will be in the form <header> => <value>.
example:
['Content-Type'] => ['text/xml']
enjoy :)
Tuesday, November 24, 2009
PHP Curl download via FTP access - Part 1
Downloading files via FTP in PhP is fairly easy even if you need FTP access. If your host supports it you just grab the file via PhP's fgets() function (or fread() if u need binary-safe). If you do need FTP access heres a quick snippet to connect:
additionally you can add a file_put_contents($local, $data); to write it to your local server.
However if your host doesn't support this you'll have to go with the curl method. First step is to make sure the library is installed on your server. Most come with it pre-installed these days so you should be good but to check simple echo phpinfo() and search for "curl" to see what you have.
Next step is to login to FTP via curl which you can do using this format:
it is a good idea to urlencode() your $ftpUser and $ftpPass because if it has a semicolon or at symbol most servers won't know how to interpret what you are trying to do. (Took me like an hour to figure out why it wasn't working for me :\). Once you know you have access you can continue the script and download a remote file to your local server as follows:
Hope this saves someone hours of time researching.
$fp = ftp_connect($ftpServer);
$lh = ftp_login($fp, $ftpUser, $ftpPass);
$data = fgets($fp);
And you have your file;additionally you can add a file_put_contents($local, $data); to write it to your local server.
However if your host doesn't support this you'll have to go with the curl method. First step is to make sure the library is installed on your server. Most come with it pre-installed these days so you should be good but to check simple echo phpinfo() and search for "curl" to see what you have.
Next step is to login to FTP via curl which you can do using this format:
$url = "ftp://$ftpUser:$ftpPass@$ftpServer";it is a good idea to urlencode() your $ftpUser and $ftpPass because if it has a semicolon or at symbol most servers won't know how to interpret what you are trying to do. (Took me like an hour to figure out why it wasn't working for me :\). Once you know you have access you can continue the script and download a remote file to your local server as follows:
$ftpServer = <hosted_file>;
$ftpUser = urlencode(<ftp_user_name>);
$ftpPass = urlencode(<ftp_password>);
$local = <local_file_location>; //be sure to use full path here
$url = "ftp://$ftpUser:$ftpPass@$ftpServer";
$cp = curl_init();
$fp = fopen($local, "w");
curl_setopt($cp, CURLOPT_URL,$url);
curl_setopt($cp, CURLOPT_FILE, $fp);
curl_setopt($cp, CURLOPT_HEADER, 0);
curl_exec($cp);
curl_close($cp);
fclose($fp);
Hope this saves someone hours of time researching.
Tuesday, November 3, 2009
Setting Sitewide URL Prefix in Zend
So recently I came across the need to put a site into a test folder. Now I have done this in the past and it is very easy using a global domain name variable to change your domain from http://something.com/ to http://something.com/test/. If you have you own routing class you can just tell it to ignore the first parameter in the URI.
But here is the problem: I was trying to do this with the Zend routing class on a site that was already configured at setup with all its routing rules. Originally I tried just prepending 'test/' to all of the existing rules but that caused more complications than I had time to fix. I tried Googling a quick fix for this but could find nothing other than how to reroute one rule to another or forward to another controller. While it was useful information and I may need it in the future it was unrelated to my issue.
What I ended up doing was digging through the Zend_Controller_Front class to see what I could find. And voila I came across a class variable _baseUrl. Looking through the class methods I quickly found the setBaseUrl() method. After smacking myself on the head for not thinking of this earlier I then set called the already set controller class to call
Hope this saves someone else a couple hours of searching.
But here is the problem: I was trying to do this with the Zend routing class on a site that was already configured at setup with all its routing rules. Originally I tried just prepending 'test/' to all of the existing rules but that caused more complications than I had time to fix. I tried Googling a quick fix for this but could find nothing other than how to reroute one rule to another or forward to another controller. While it was useful information and I may need it in the future it was unrelated to my issue.
What I ended up doing was digging through the Zend_Controller_Front class to see what I could find. And voila I came across a class variable _baseUrl. Looking through the class methods I quickly found the setBaseUrl() method. After smacking myself on the head for not thinking of this earlier I then set called the already set controller class to call
Zend_Controller_Front::setBaseUrl('/test/'); And like magic the Zend controller started recognizing all my URL's that were prepended with '/test/'.Hope this saves someone else a couple hours of searching.
Monday, March 23, 2009
Ticket Broker Software
Recently at SEO Webowrks I have finished designing a small package that quickly creates a database-driven, SEO friendly website for ticket brokers who are trying to get started or having bad luck with their current website. This package can be uploaded in 5 minutes and with little changes to the code the site can be made to behave differently than the other sites. What makes the sites unique from each other is that each site comes with an admin panel so that the site owner can add any artist or event they want with any information they want about that subject. When they add an artist a page will be created for that artist with a link to their checkout (through ticket network or other ticket company providers).
Designed using the MVC model any site can be personalized based on request with little effort. Most of the design is CSS based and will soon be implemented with divs instead of tables (i know, yuck!).
For more information check out the article at Ticket News or the site at Ticket Website HQ
Designed using the MVC model any site can be personalized based on request with little effort. Most of the design is CSS based and will soon be implemented with divs instead of tables (i know, yuck!).
For more information check out the article at Ticket News or the site at Ticket Website HQ
Thursday, November 20, 2008
Pulling Variables From Database
Recently I was working with a database and needed a way to have variables on each page but each page needed different content. i know this can be done with templating but I didn't want to have to import a big templating software for this one thing. I did a few searches online and after a while of searching saw mention of PhP's eval function.
It was a bit tricky to get working but here is the result:
eval("\$string = \"$string\";");
echo $string;
$string is the result from the database and can contain a string like "we have $variable1 for your $variable2!". The eval function takes car of parsing the PhP variable...very useful.
Thought this might be useful to anyone caring to read =)
It was a bit tricky to get working but here is the result:
eval("\$string = \"$string\";");
echo $string;
$string is the result from the database and can contain a string like "we have $variable1 for your $variable2!". The eval function takes car of parsing the PhP variable...very useful.
Thought this might be useful to anyone caring to read =)
Gmail's New Themes
So I originally heard about the new themes for Gmail and thought well that's pretty cool that they,re finally doing that. But I decided to check it out and the last theme caught my eye - Terminal. A little something every programmer can appreciate...

check it out by going to Gmail Themes and logging to your gmail account
check it out by going to Gmail Themes and logging to your gmail account
Thursday, November 6, 2008
Site Keyword Crawler
Recently I have been interested in PhP array functions and Regular Expressions (abbreviated as RegExp). I have found it is very easy to find the major keywords that are inside a string of text using the following code:
Basically it breaks apart the content into an array of tokens and checks for duplicates. As it stands this will grab anything with a space between as a token so things like 'alt="text' will be tagged as a token. Some modifications are needed for this to work on an HTML document like some fancy reg exp searches =). I will keep posting with any updates to this function...
function getKeyWords($content){
$tokens=explode(" ", $content);
$keywords=array("num_words"=>1);
foreach ($tokens as $word){
if (!array_key_exists($word, $keywords)){
//echo "word not found! $word
";
$keywords[$word]=1;
}else
$keywords[$word]++;
$keywords['num_words']++;
}
return $keywords;
}
Basically it breaks apart the content into an array of tokens and checks for duplicates. As it stands this will grab anything with a space between as a token so things like 'alt="text' will be tagged as a token. Some modifications are needed for this to work on an HTML document like some fancy reg exp searches =). I will keep posting with any updates to this function...
Thursday, October 23, 2008
Using functions in form file
So I recently ran into the problem of trying to grab $_REQUEST variables from a page and use them in a function on the same page. My error was Fatal error: Call to undefined function myFunction...
The structure of my code was check if the request had been submitted and perform page logic, otherwise display the form. The apparent problem was that my function was inside the page logic after the if statement checked for the request. Because it was after the if statement it never got parsed ahead of time and therefore never really existed before the call was made.
To fix the problem I simply moved my function to the top of my pHp code (before the if statement) and everything works fine.
The structure of my code was check if the request had been submitted and perform page logic, otherwise display the form. The apparent problem was that my function was inside the page logic after the if statement checked for the request. Because it was after the if statement it never got parsed ahead of time and therefore never really existed before the call was made.
To fix the problem I simply moved my function to the top of my pHp code (before the if statement) and everything works fine.
Wednesday, October 22, 2008
Party Fun 411 - a party directory
My most recent project at SEO Webworks is Party Fun 411. Party Fun 411 is a party directory where you can find any kind of service you would need for any city or state in the US. Only the cities that have vendors listed though will show up so you don't waste your time looking through empty directories. I discovered vendors for types of companies I didn't even know existed such as chocolate fountains. Did you know there are vendors out there that let you rent them? I didn't. You can also find any of your normal party services such as Limousines or "Party Buses" and Planners for things like weddings or even corporate events.
Party Fun also helps out the small vendor companies that offer party services because it allows them to build PR (Google's page ranking system). Our site helps focus keywords such as wedding planning to vendors for wedding planning so even the little guys have a chance at being found.
I think that Party Fun 411 has a lot of potential to grow and be that much more valuable to its customers and vendors.
Party Fun also helps out the small vendor companies that offer party services because it allows them to build PR (Google's page ranking system). Our site helps focus keywords such as wedding planning to vendors for wedding planning so even the little guys have a chance at being found.
I think that Party Fun 411 has a lot of potential to grow and be that much more valuable to its customers and vendors.
Friday, January 11, 2008
Creating static pages from a database
For my most recent project I will be creating a sign-up sheet that will generate static pages when the information is entered. The reason the pages will be static is so they can be crawled by search engine spiders. A spider cannot read dynamically created pages because it only looks at what is stored on the server and that would be the php script which is not friendly at all to them. The only block of information that I will not have to store in the database is the text block because it will only be written out to the pages for that particular user. The rest of the information will have to be called from other pages.
Creating the page for the vendor is easy (if you've used xtemplates before). Its just a matter using xtemplate function xtpl->assign() to replace the text block and other info where it is needed.
The first mildly challenging aspect I encountered was the multiple select list where the user can choose multiple options with ctrl-click as so:
This data has to be stored somewhere and the most difficult part was getting the array to pass to the php script. In my script I had:
< br />
Which I was sure would work but I kept getting an error on my foreach statement. After some research on html forms I found that the value to be passed as an array to a script had to be defined as name="my_name[]". Html needs the [] to show the script that it is an array otherwise it will just pass the first value. Obviously a foreach() statement won't work on an non-array type so this is why that code was breaking.
The next bigger challenge I have is to create site maps to all of these pages being created and also create links on the bottom of the user's page to some pages from other users, based on group, as kind of a minimap. Again all my pages have to be static so php cannot reside on the page and call the database. I looked into the Apache server mod_rewrites and there is no way to create a static page with php on it. My first idea was to write a script to parse the php pages using the ob_start() function which will store all proceeding information on an internal buffer which is sent to the browser's buffer on ob_end_flush(). This buffered content (which will now be parsed by the browser) can be stored in any string. I was then going to take this content and write it to a new .html file under the same name. This takes a lot of time because of the amount of pages being created and buffered and space because I would have to keep the .php file in the event the database was updated I would have to update the .html.
But then I got an idea which was much simpler and straight forward and would save all the extra work from my previous idea. My idea is to not even put the php on the page in the first place. I can just use the xtpl->assign('var', 'content') function here as well and put the php code in the content as xtpl->assign('var', 'php_code'). The browser will parse the php code before it gets sent to the xtpl function saving me a lot of work. The only thing I need to do now is to make my code more modular so I can write a script to update the pages using this philosophy every so often for when the database is updated.
Creating the page for the vendor is easy (if you've used xtemplates before). Its just a matter using xtemplate function xtpl->assign() to replace the text block and other info where it is needed.
The first mildly challenging aspect I encountered was the multiple select list where the user can choose multiple options with ctrl-click as so:
This data has to be stored somewhere and the most difficult part was getting the array to pass to the php script. In my script I had:
if(isset($cities)){
foreach($cities as $value){
$query="INSERT IGNORE INTO `***` (`user`, `cities`) VALUES ('".$user_name."', '".$value."');";
mysql_query($query) or die('Failed to update user to cities: '.mysql_error());
}
}
< br />
Which I was sure would work but I kept getting an error on my foreach statement. After some research on html forms I found that the value to be passed as an array to a script had to be defined as name="my_name[]". Html needs the [] to show the script that it is an array otherwise it will just pass the first value. Obviously a foreach() statement won't work on an non-array type so this is why that code was breaking.
The next bigger challenge I have is to create site maps to all of these pages being created and also create links on the bottom of the user's page to some pages from other users, based on group, as kind of a minimap. Again all my pages have to be static so php cannot reside on the page and call the database. I looked into the Apache server mod_rewrites and there is no way to create a static page with php on it. My first idea was to write a script to parse the php pages using the ob_start() function which will store all proceeding information on an internal buffer which is sent to the browser's buffer on ob_end_flush(). This buffered content (which will now be parsed by the browser) can be stored in any string. I was then going to take this content and write it to a new .html file under the same name. This takes a lot of time because of the amount of pages being created and buffered and space because I would have to keep the .php file in the event the database was updated I would have to update the .html.
But then I got an idea which was much simpler and straight forward and would save all the extra work from my previous idea. My idea is to not even put the php on the page in the first place. I can just use the xtpl->assign('var', 'content') function here as well and put the php code in the content as xtpl->assign('var', 'php_code'). The browser will parse the php code before it gets sent to the xtpl function saving me a lot of work. The only thing I need to do now is to make my code more modular so I can write a script to update the pages using this philosophy every so often for when the database is updated.
Tuesday, January 8, 2008
So since I can't do php in a comment...
I think that the bitwise or was probably the cause of the problem. I actually didn't notice until you pointed it out. But I just ended up re-doing the database (basically copy and paste) so I could create this much nicer query:
$query = "select * from Artists"
$result = mysql_query($query)
if (mysql_num_rows($result) == 0){
echo 'nothing here...'
}
else{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo ""
$out = ""
echo $out
echo $row['state']
echo " "
$out = ""
echo $out
echo $row['city']
echo " "
$out = ""
echo $out
echo $row['venue']
echo "
"
}
}
This was just to get it to work so I could display something. When I'n not working on my new project i will try to work out the original setup (which I still kept incase). As it is right now it is very difficult to update the database because the amount of data for each column is different so there are a lot of blank rows. This just makes messy MySQL updates when trying to find the first blank row which isn't very efficient since I want to be able to upload multiple rows at a time.
I think that the bitwise or was probably the cause of the problem. I actually didn't notice until you pointed it out. But I just ended up re-doing the database (basically copy and paste) so I could create this much nicer query:
$query = "select * from Artists"
$result = mysql_query($query)
if (mysql_num_rows($result) == 0){
echo 'nothing here...'
}
else{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "
$out = "
echo $out
echo $row['state']
echo "
$out = "
echo $out
echo $row['city']
echo "
$out = "
echo $out
echo $row['venue']
echo "
}
}
This was just to get it to work so I could display something. When I'n not working on my new project i will try to work out the original setup (which I still kept incase). As it is right now it is very difficult to update the database because the amount of data for each column is different so there are a lot of blank rows. This just makes messy MySQL updates when trying to find the first blank row which isn't very efficient since I want to be able to upload multiple rows at a time.
Thursday, January 3, 2008
Multiple MySQL Queries in PhP
The problem with using multiple queries from multiple tables is that the MYSQL_ASSOC or MYSQL_NUM both only seem to work on the latest query even if the queries and results are stored under different variables. Here is the code:
echo '
?>
And all that appears is the last column. The tags are being read correctly because the result remains in the correct column it just doesn't seem to read the first two queries.
My solution for now is just to move the tables into one table which isn't most efficient for the database end but I think that can be sacrificed for now for PhP efficiency.
echo '
';';
require ('dbconnect.inc');
$query_state = "select state from States;";
$result_state = mysql_query($query_state);
$query_city = "select city from Cities;";
$result_city = mysql_query($query_city);
$query_venue = "select venue from Venues;";
$result_venue = mysql_query($query_venue);
if (mysql_num_rows($result_state) == 0 | mysql_num_rows($result_city) == 0 | mysql_num_rows($result_venue) == 0){
echo 'nothing here...';
}
else{
while ($row1 = mysql_fetch_array($result_state, MYSQL_ASSOC) | $row2 = mysql_fetch_array($result_city, MYSQL_ASSOC) | $row3 = mysql_fetch_array($result_venue, MYSQL_ASSOC)){
echo ""; ";
$out = ""; ";
echo $out;
echo $row1['state'];
echo "
$out = ""; ";
echo $out;
echo $row2['city'];
echo "
$out = "";
echo $out;
echo $row3['venue'];
echo "
}
}
echo '
?>
And all that appears is the last column. The
My solution for now is just to move the tables into one table which isn't most efficient for the database end but I think that can be sacrificed for now for PhP efficiency.
Wednesday, January 2, 2008
Dynamically Creating Pages
So here's a funny story...recently I was trying to use PhP inside a page I have created dynamically. I was just using simple echo statements to try to output HTML to the page. Seems simple right? For some reason I couldn't figure out it just wasn't working. So I did a lot of research on single quotes and double quotes and PhP functions such as htmlspechialchars() and addslashes(). None of those worked. Then I decided to look at the function that was creating the page. Turns out it was creating a .HTML page and not a .php page so it could not read the PhP. I felt foolish after that. Anyway I learned some things I would have to deal with later so it wasn't a complete waste of time.
Thursday, December 20, 2007
On Using Templates
I am starting a project for SEOWeboworks in downtown Plymouth as my first real work experience. I am working a test project they want me to work on before I start doing actual work. The project uses a templating structure that will auto-generate similar web pages for their Ticketing website replacing the artist's name on each page. I have tried using php classes with the str_replace() function but that failed. It recognizes the variable I want to replace and the variable I want to replace it with but somehow replaces it with blank space. The following was my attempt:
class template {
//this template will replace {artist} with the artist's name
var $template;
//This method will import the contents of the template file into the template property of the class
function load_tpl($filename) {
$this->template = file_get_contents($filename);
}
//This method will replace the tag_names found in the template with the given replacement data
function parse_tags($tag_name, $replacememt) {
$this->template = str_replace($tag_name, $replacement, $this->template);
echo "replace ".$tag_name." with ".$replacememt;
}
//This method will output the contents of the template file to the browser
function output() {
echo $this->template;
}
}
?>
and that failed
So now I have decided to try XTemplates and we'll see how that goes.
Update:
So the new XTemplate setup is working props to Peter for the tips on how to use it. Here it is:
include_once('xtemplate.class.php');
//load new xtemplate
$xtpl = new XTemplate('artist_page.xtpl');
//this template will replace {artist} with the artist's name
$artist=$_POST["artist"];
$xtpl->assign('artist', $artist);
//output new page
$xtpl->parse('main');
$xtpl->out('main');
?>
definitely much simpler than the previous code block.
Now on to add more functionality!
class template {
//this template will replace {artist} with the artist's name
var $template;
//This method will import the contents of the template file into the template property of the class
function load_tpl($filename) {
$this->template = file_get_contents($filename);
}
//This method will replace the tag_names found in the template with the given replacement data
function parse_tags($tag_name, $replacememt) {
$this->template = str_replace($tag_name, $replacement, $this->template);
echo "replace ".$tag_name." with ".$replacememt;
}
//This method will output the contents of the template file to the browser
function output() {
echo $this->template;
}
}
?>
and that failed
So now I have decided to try XTemplates and we'll see how that goes.
Update:
So the new XTemplate setup is working props to Peter for the tips on how to use it. Here it is:
include_once('xtemplate.class.php');
//load new xtemplate
$xtpl = new XTemplate('artist_page.xtpl');
//this template will replace {artist} with the artist's name
$artist=$_POST["artist"];
$xtpl->assign('artist', $artist);
//output new page
$xtpl->parse('main');
$xtpl->out('main');
?>
definitely much simpler than the previous code block.
Now on to add more functionality!
Wednesday, December 19, 2007
Its the beginning of the end
I had been posting (if infrequently) in a previous blog on my school's site. But I thought it would be a good idea to get out there on the interweb and start my on personal blog. I am currently a CS major at Plymouth State University. I will be using this blog to post my ideas, breakthroughs and projects and other random stuff.
Subscribe to:
Posts (Atom)