For Version 3.x
As of version 3, Squirrelcart has built in support for creating your own pages via link and content records in your control panel. This is explained here. That is the recommended approach to create pages that appear within Squirrelcart's storefront.
If you would prefer to create pages manually that use your own PHP files in a similar fashion to the version 2.x code explained above, you can still do that. Here's how.
Part 1
In order to make the changes described below, you need to know how to properly modify templates in Squirrelcart via a custom theme. If you aren't familiar with how to do that, it is very important to read this topic first.
You need a way to tell Squirrelcart what file to grab content from. You can do this via a GET query in the URL as follows:
http://www.example.com/store.php?page=test
With that query, you are sending a variable named 'page', which can be accessed via PHP like this example:
PHP Code:
<?php print $_GET['page']; ?>
PHP can include any file and will show it's contents as in this example:
PHP Code:
<?php include 'test.php'; ?>
Now, you may be thinking that you could send a query like "store.php?page=test.php" and then just do this and be done with it:
PHP Code:
<?php include $_GET['page']; ?>
DO NOT DO THAT!! REPEAT, DO NOT DO THAT!! (oh, and definitely don't do that!)
It is a HUGE security risk. With that method, they can include any page on your server and use it for hacking purposes. If you have http wrappers enabled in PHP, someone could even include a file on a remote site, and leave you open to some major hacking.
The best way to handle this is to find this code in your store_main.tpl.php template file:
PHP Code:
<?php print $Cart_Content; ?>
Directly before that line, add this code:
PHP Code:
<?php
// make sure $page is a word only
if (preg_match('/^[\w-]+$/',$_GET['page']) && file_exists("$_GET[page].php")) {
ob_start();
print "<div class=\"sc_content sc_main_content\">";
include "$_GET[page].php";
print "</div>";
$Cart_Content = ob_get_clean();
}
?>
The first part of the if statement makes sure that the value of page is a word. It keeps hackers from sending anything non alphanumeric, which would allow them to pass URLs, dots (../../) to traverse up your directory structure, etc...
The second part of the if statement will include the page ONLY if it exists inside your web root.
After adding that code, put a file named "test.php" in your web root folder and put some test HTML in it:
Code:
<b>Hello World!</b>
Now, enter the following URL using your own domain name:
http://www.example.com/store.php?page=test
If you did this right, you should see the contents of test.php inside the content area of your storefront page.
Now, for those of you that want more, read on...
Part 2
This part requires that you've already followed the instructions in Part 1 above. If you haven't, then do that first before proceeding.
Now, you should have the ability to create links to your own pages, and can still keep them in the design you have setup for your storefront. This method improves on the above by:
1. Allowing you to dynamically change the page title, and the "keywords" and "description" meta tags
2. Allowing you to use the actual page name in the link, instead of the query string URL. In other words, you can do this:
http://www.example.com/test.php
Instead of:
http://www.example.com/store.php?page=store
This gives you an advantage with search engines indexing these pages.
Open the test.php file you made in Part 1, and add this to the very top:
PHP Code:
<?php
if (!$_GET['page']) {
$_GET['page'] = "test";
$Title = "My test page";
$Keywords = "my dog has fleas";
$Description = 'this is a test of the emergency broadcast system';
include "store.php";
return;
}
?>
If you renamed your storefront page to something other than store.php, change the string store.php in the code above to match the name of your storefront page.
Now, save the page and load it in a browser:
http://www.example.com/test.php
You should see the same thing you saw when you went to http://www.example.com/store.php?page=test
Now, you have a nicer URL. Look up at the window's title bar and you should also see you have a page title. If you view source on the page, you'll see something like this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta name="title" content="My test page">
<meta name="keywords" content="my dog has fleas">
<meta name="description" content="this is a test of the emergency broadcast system">
<title>My test page</title>
<!-- etc... -->
You can put any HTML (or PHP) you like in your pages, as long as you have that PHP code section at the top.