marty.net 1001 Postcards Love Love Love Meep Meep ZenZodiac DailyQuotation

YOU ARE HERE:
How to embed cpshop in a PHP page

HOME

CPSHOP|

|

|

EMAIL MARTY
  marty.net message board
  « How to embed cpshop in a PHP page »
Welcome, Guest. Please Login or Register.
12/12/17 at 17:53:43
Home Help Search Login Register
   marty.net message board
   About cpshop
   Tutorials
   How to embed cpshop in a PHP page
(Moderator: Marty)
Pages: 1 2 3 4 5 6 7 » Reply Notify of replies Send the topic Print 
   Author  Topic: How to embed cpshop in a PHP page  (Read 64363 times)
Marty
Administrator Dragon
*****

Gender: male
Posts: a whole lot



That's me. :)
   

WWW E-Mail
How to embed cpshop in a PHP page
« on: 06/18/02 at 05:00:48 »
Reply with quote Modify message

This has been a popular request, so I'm glad to finally oblige in cpshop 1.3b.



  • Step 1: Make 2 quick changes to your cpshop.cgi file.

    1a: set the $script_dir variable

    Near the top of your cpshop.cgi file you'll find a line like this:



    If you've already got something in between those quotes, then you've already done this part.  But if you haven't, you need to put the absolute path to your cpshop folder in between those quotes, being sure to end it with a slash.  (You might be able to find this out with the "pwd" command in telnet.  Otherwise, just ask your system administrator; or ask me, and I'll try to figure it out.)

    Here's an example.  If your cpshop script is located in a folder called /home/httpd/mysite/cgi-bin/store, then you would put this at the top of the script:



    1b: fix the Content-Type line

    If you installed cpshop prior to version 1.3b, then your cpshop.cgi file has two lines just like this, near the end of the file:



    Change the first of the two so it looks like this:



  • Step 2: Make a very boring cpshop template.  Basically, you should create a file with nothing but a single <[content]> tag in it, like this:



    Save this file (perhaps as cptemplate.html), and upload it to your cpshop directory.  On the admin screen, set this file as the default HTML template.

  • Step 3: Set the "use Clean URLs" option in cpadmin to "use query strings".  

    This is because cpshop will be using query strings to pass information between the PHP page and itself.  (thanks Hex Angel for pointing this out)

  • Step 4: Setup your php file.  You'll need to know three things for this step:

    Insert code like this into your PHP file, wherever you want your store content to appear:



    So here's an example using the file names and URLs above:



    BE SURE THAT YOU USE BACKTICKS (`) IN THE $str LINE, NOT REGULAR SINGLE OR DOUBLE QUOTE MARKS.  (THE BACKTICK CHARACTER IS USUALLY FOUND IN THE UPPER-LEFT CORNER OF THE KEYBOARD, WITH THE ~ CHARACTER.)

    ALSO: MAKE SURE THE $str LINE ALL APPEARS ON THE SAME LINE.

    Upload the PHP file to your server, and try accessing it through your browser.  It should work just fine.


If you want to customize the content of your store more, you can use the admin panel, or customize your store template file.  All the functions in the script will still work.
« Last Edit: 03/12/06 at 17:34:50 by Marty » Logged

--
Regards,
Marty·.¸¸.·´¯`·.¸¸.-> marty@marty.net
nolageek
Guest

E-Mail
Re: How to embed cpshop in a PHP page
« Reply #1 on: 06/18/02 at 10:07:31 »
Reply with quote Modify message

Wow.  You rock.  I'll install this when I get home and let you know how it all works.

Not sure if you know about Postnuke.  It's a very popular PHP Portal system.  Would you mind if I made a module around cpshop that I let people download.  I WILL NOT include the actual cpshop script, just the single PHP wrapper page that would be called to get it running.  There has been several half-assed CafePress scripts floating around but nothing quite like cpshop.  I think there would be a LOT of interest in this.
Logged
Marty
Administrator Dragon
*****

Gender: male
Posts: a whole lot



That's me. :)
   

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #2 on: 06/18/02 at 12:38:46 »
Reply with quote Modify message

I don't mind at all, it sounds like a great idea.  Just let me know where you end up putting it, and I'll add a link to it to the site.

I've seen a bunch about PostNuke, but, since I'm not a PHP person, I really don't know how to actually use it.  From what I have seen, however, it looks pretty powerful.
Logged

--
Regards,
Marty·.¸¸.·´¯`·.¸¸.-> marty@marty.net
SmokinL
White Dragon
**

Posts: 22



Breeding a whole new generation of backyard pitmasters!
8170046 8170046   xlentbbq xlentbbq  

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #3 on: 07/27/02 at 15:35:33 »
Reply with quote Modify message

Ok Marty,

Time for a challenge.  Made the changes and the php file showed the script (Yea!!!), but click on a link, and you'll see the storefront page again...and again...and again.  (Hmmm.)

Any ideas?

Here is the location:

http://www.thebackyardbbq.com/hr/phpstore/store.php
Logged

Nuttin Betta Than A Perfectly Smoked Piece Of Meat!
SmokinL
White Dragon
**

Posts: 22



Breeding a whole new generation of backyard pitmasters!
8170046 8170046   xlentbbq xlentbbq  

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #4 on: 07/27/02 at 18:01:33 »
Reply with quote Modify message

Weird.  Cleared my cache and now getting an error.  It now says that the .config file need to be gernerated.  It works fine going direct: http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi

Here is my cpshop.cgi file:


Code:
#!/usr/bin/perl

$script_dir = "/home/backbbq/www/hr/cgi-bin/store/"; # IF YOU ADD THIS, BE SURE TO INCLUDE THE TRAILING SLASH!

#####################################################################
# This script is copyright (c)2002 - 1001 Media Group.              #
# Please do not distribute it without permission.                   #
#####################################################################
#                                                                   #
#        #####   ######    #####   ##   ##   ######   ######        #
#       ##   ##  ##   ##  ##   ##  ##   ##  ##    ##  ##   ##       #
#       ##       ##   ##  ##       ##   ##  ##    ##  ##   ##       #
#       ##       ######    #####   #######  ##    ##  ######        #
#       ##       ##            ##  ##   ##  ##    ##  ##            #
#       ##   ##  ##       ##   ##  ##   ##  ##    ##  ##            #
#        #####   ##        #####   ##   ##   ######   ##            #
#                                                                   #
########### ports multiple CafePress stores to your server ##########
################ http://cgi.marty.net/scripts/cpshop/ ###############

require "${script_dir}cp----.lib";
require "${script_dir}cp----.lib";
&prepare;


$hacked = 0;

if ($hacked) {

   ** If statement removed for posting on disc. board **


   unless (@ARGV) {
       print "Content-Type: text/html\n\n";
   }
   print $html;
   exit;
}

1;
« Last Edit: 07/27/02 at 18:10:06 by SmokinL » Logged

Nuttin Betta Than A Perfectly Smoked Piece Of Meat!
SmokinL
White Dragon
**

Posts: 22



Breeding a whole new generation of backyard pitmasters!
8170046 8170046   xlentbbq xlentbbq  

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #5 on: 07/27/02 at 21:57:49 »
Reply with quote Modify message

Now this works...kind of:


Code:
<?php
ob_start();
ob_implicit_flush(0);
/* $script_name = ; */
virtual ("../cgi-bin/store/cpshop.cgi");
ob_end_clean();
?>


The problem with this is, it works like a SSI call.  When a link is chosen, it takes you to the actual script, bypassing the site's overall template.  I unfortunately had to use ../ to allow this script to be called from a subdirectory and a subdomain.

Hmmm.  Still searching.
Logged

Nuttin Betta Than A Perfectly Smoked Piece Of Meat!
Marty
Administrator Dragon
*****

Gender: male
Posts: a whole lot



That's me. :)
   

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #6 on: 07/27/02 at 22:34:39 »
Reply with quote Modify message

Here's an idea: try setting the Clean URLs variable to "No".  I have a feeling that might be the problem.

Of course, you'll have to reinsert the original PHP code.

Let me know what happens.
Logged

--
Regards,
Marty·.¸¸.·´¯`·.¸¸.-> marty@marty.net
SmokinL
White Dragon
**

Posts: 22



Breeding a whole new generation of backyard pitmasters!
8170046 8170046   xlentbbq xlentbbq  

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #7 on: 07/28/02 at 08:04:19 »
Reply with quote Modify message

Well, changing that didn't do anything.  Still acts like SSI.  I still believe your code is more on the right track of what needs to be done.  When you pull up the page http://hr.thebackyardbbq.com/phpstore/store.php, all store IDs are set to it's url:


Code:
http://www.thebackyardbbq.com/hr/phpstore/store.php/333096219
http://www.thebackyardbbq.com/hr/phpstore/store.php/2959405812
http://www.thebackyardbbq.com/hr/phpstore/store.php/588393292
http://www.thebackyardbbq.com/hr/phpstore/store.php/1455160342
http://www.thebackyardbbq.com/hr/phpstore/store.php/1239812155
http://www.thebackyardbbq.com/hr/phpstore/store.php/3787995356
http://www.thebackyardbbq.com/hr/phpstore/store.php/2599484152
http://www.thebackyardbbq.com/hr/phpstore/store.php/3621611608



where as the SSI style, http://hr.thebackyardbbq.com/phpstore/store1.php, all IDs are set to the actual cgi:


Code:
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/333096219
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/2959405812
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/588393292
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/1455160342
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/1239812155
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/3787995356
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/2599484152
http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi/3621611608


Interesting thing, when one of the links are selected in the store.php file with your original code, a 404 error is not displayed, rather the store's menu is redisplayed.  I wonder if creating an alias would work, so we are always calling that to help process.  Another question I had, based on a different error I got, was if the .config file was being instantiated when using the .php file.
« Last Edit: 07/28/02 at 08:05:29 by SmokinL » Logged

Nuttin Betta Than A Perfectly Smoked Piece Of Meat!
Marty
Administrator Dragon
*****

Gender: male
Posts: a whole lot



That's me. :)
   

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #8 on: 07/28/02 at 12:52:14 »
Reply with quote Modify message

Do me a favor: zip up the .php file (since I can't see the source), along with your cpshop.cgi file, and email them to me at marty@marty.net.  I just want to make sure the code is all fine.

And for now, leave the Clean URLs setting to "use query strings", at least until we can get this figured out.

By the way, we will get it figured out.  I'm going out with visitors for much of the day, but I'll be home tonight, and if there's a problem, I'll find it.

And if you wanted to see it, here's the link for the working PHP store:

http://www.marty.net/home/marty/phpstore/index.php

and the PHP source for that page:

http://www.marty.net/home/marty/phpstore/index.phps

Maybe that'll shed some light on the subject.
Logged

--
Regards,
Marty·.¸¸.·´¯`·.¸¸.-> marty@marty.net
SmokinL
White Dragon
**

Posts: 22



Breeding a whole new generation of backyard pitmasters!
8170046 8170046   xlentbbq xlentbbq  

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #9 on: 07/28/02 at 14:29:37 »
Reply with quote Modify message

Ok, found the problem.

In the tutorial above, here is what is listed to match in the php file:


Code:
<?php
$qs = urlencode($HTTP_SERVER_VARS['QUERY_STRING']);
$str = `/home/domains/marty.net/cgi/store/cpshop.cgi http://www.marty.net/phpstore/store.php http://www.marty.net/cgi/store/cpshop.cgi $qs`;
echo $str;
?>


So, I did this:


Code:
<?php
$qs = urlencode($HTTP_SERVER_VARS['QUERY_STRING']);
$str = `/home/backbbq/public_html/hr/cgi-bin/store/cpshop.cgi http://www.thebackyardbbq.com/hr/phpstore/store.php http://www.thebackyardbbq.com/hr/cgi-bin/store/cpshop.cgi $qs`;
echo $str;
?>


Well, in your example, you have this:


Code:
<?php

   $qs = urlencode($HTTP_SERVER_VARS['QUERY_STRING']);
   $str = `/htdocs2/1001/cgi/marty/cpshop/dev/php http://www.marty.net/phpstore/ http://cgi.marty.net/cgi/marty/cpshop/dev/php $qs`;
   echo $str;

?>


So, I did this:


Code:
<?php

   $qs = urlencode($HTTP_SERVER_VARS['QUERY_STRING']);
   /* $str = `/htdocs2/1001/cgi/marty/cpshop/dev/php http://www.marty.net/phpstore/ http://cgi.marty.net/cgi/marty/cpshop/dev/php $qs`; */
   $str = `/home/backbbq/public_html/hr/cgi-bin/store/cpshop.cgi http://hr.thebackyardbbq.com/phpstore/store2.php http://hr.thebackyardbbq.com/cgi-bin/store/cpshop.cgi $qs`;
     echo $str;

?>


And it worked!!!  Can you see the differences?  Subdomain diction for some reason threw it off.  Weird.  The page works both under hr.thebackyardbbq.com and www.thebackyardbbq.com/hr, even though the coding was specific.  

Thanks for posting up the php file you created.  That helped a lot.  Now, time to make it into a module.
« Last Edit: 07/28/02 at 14:32:40 by SmokinL » Logged

Nuttin Betta Than A Perfectly Smoked Piece Of Meat!
Marty
Administrator Dragon
*****

Gender: male
Posts: a whole lot



That's me. :)
   

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #10 on: 07/28/02 at 17:18:04 »
Reply with quote Modify message

Well, I'm not necessarily sure why that would have made a difference, but if it works it's all good.

Let me know if you need anything else.
Logged

--
Regards,
Marty·.¸¸.·´¯`·.¸¸.-> marty@marty.net
ironwulf
Green Dragon
*

Posts: 3



Go Scots!
   

E-Mail
Re: How to embed cpshop in a PHP page
« Reply #11 on: 04/20/03 at 13:23:34 »
Reply with quote Modify message

To find out the absolute path...
just create a php file with a parse error and upload to that path (error reporting turned on?)

eg

<?php
echo "blah"
?>

It should say something like:

Error: Expecting ';' in /home/usr/public_html/CPANELUSER/cgi-bin/SCRIPTNAME.php on line 2
Logged
david@zatz.com
White Dragon
**

Posts: 11



Go Scots!
   

E-Mail
Re: How to embed cpshop in a PHP page
« Reply #12 on: 11/18/03 at 23:41:22 »
Reply with quote Modify message

Can you please discuss how this embed code example works:


Code:
<?php

  $qs = urlencode($HTTP_SERVER_VARS['QUERY_STRING']);
  $str = `/htdocs2/1001/cgi/marty/cpshop/dev/php http://www.marty.net/phpstore/
http://cgi.marty.net/cgi/marty/cpshop/dev/php $qs`;
  echo $str;

?>


I want to see if I can use another hosting language (Frontier/UserTalk/Manila) to do the same thing, but first, I really need to know what you're doing there, and what it means.

Here's what I think I've figured out so far:

  • qs$ gets the query data, encodes it in some way, and passes it to your routine.
  • Your entire routine is executed, some page text is generated, and that's dumped into str$
  • str$ is passed back to PHP and is what is returned to the user's browser


I guess it's the stuff inside the grave accents I don't really understand.

Thanks!

PS: Even though I'm using an obscure tool, if I figure it out, I'll post it here for any other obscure tool users.
Logged
Marty
Administrator Dragon
*****

Gender: male
Posts: a whole lot



That's me. :)
   

WWW E-Mail
Re: How to embed cpshop in a PHP page
« Reply #13 on: 11/19/03 at 00:02:28 »
Reply with quote Modify message

You pretty much have it.

$qs = urlencode($HTTP_SERVER_VARS['QUERY_STRING']);
URL encode the query string (information in the URL coming after the ?), and remember it as a variable named $qs.

$str = `/htdocs2/1001/cgi/marty/cpshop/dev/php http://www.marty.net/phpstore/  
http://cgi.marty.net/cgi/marty/cpshop/dev/php $qs`;

Everything that appears in ` marks is the equivalent of running a command from the command line, or calling it as an "exec" call.  Essentially, this line can be rewritten as:
$str = exec "[path to cpshop.cgi file] [URL of php page] [URL of cpshop.cgi] $qs";
The command is then told to take the output of the command, and place it in the variable $str.

echo $str;
Prints the content of $str to the screen.

That's pretty much it.
Logged

--
Regards,
Marty·.¸¸.·´¯`·.¸¸.-> marty@marty.net
david@zatz.com
White Dragon
**

Posts: 11



Go Scots!
   

E-Mail
Re: How to embed cpshop in a PHP page
« Reply #14 on: 11/19/03 at 02:29:10 »
Reply with quote Modify message

OK, I'm close to groking it, I think. In your line:

$str = exec "[path to cpshop.cgi file] [URL of php page] [URL of cpshop.cgi] $qs";

It looks like the [URL of cpshop.cgi] and $qs are the real invocation url and args for cpshop, right?

But what's the purpose of [path to cpshop.cgi file] and [URL of php page] to the exec command? Are you asking for a return jump page back to the PHP?

To complicate matters more, I'm probably going to run cpshop on a different box (I hope, if I get anywhere) from the Manila server I'm trying (thinking about) integrating with.

Worse case, I'll just run a template, but that's not going to be nearly as much fun!
Logged
Pages: 1 2 3 4 5 6 7 » Reply Notify of replies Send the topic Print 
Jump to:


marty.net message board (http://www.marty.net/cgi/marty/board/messageboard)

Powered by YaBB 1 Gold - Release (Yet Another Bulletin Board)
Copyright © 2000-2001, X-Null. All Rights Reserved.