L
larry1301

  • Dec 6, 2007
  • Joined Feb 15, 2002
  • More great references. I have used some of the design patterns in the past, most the singleton, but I take a closer look at these before I proceed. Thanks.

    I didn't mention it before, but the development is in php 5.1, mySQL 5 and smarty. Stored Procedures are used for just about all database access.

    BTW, the defines aren't used outside the class. They are only used so that I can visually inspect the results. Reading

    	public static $ConservationTypes = array (
    		MAT_ARCHIVAL => array ( ALPHARAG_100_PERCENT_COTTON,ALPHARAG_ARTCARE ),
    		MAT_CONSERVATION => array ( SELECT ),
    		MAT_DECORATIVE => array ( PAPERMAT )
    	);

    is a lot easier than

    	public static $ConservationTypes = array (
    		1 => array ( 1,2 ),
    		2 => array ( 44),
    		3 => array ( 66 )
    	);

    Will never be used outside the class. I expect to change to product set of mats with some frequency so I won't be using them anywhere outside the class.

    The following is a reduced version of the generated class (class.Mat.php) as it exists right now. Everything, including the comments are generated via a script. There is a lot more data and methods than shown.

    <?php
    // Conservation Types
    define("MAT_ARCHIVAL",1);
    define("MAT_CONSERVATION",2);
    define("MAT_DECORATIVE",3);
    
    // Manufacturers
    define("BAINBRIDGE",1);
    define("CRESECENT",2);
    define("LARSON-JUHL",3);
    
    // Mat Thickness
    define("MAT_4_PLY",4);
    define("MAT_6_PLY",6);
    define("MAT_8_PLY",8);
    
    // Mat Size
    define("MAT_32X40",1);
    define("MAT_40X60",2);
    
    // Mat Types
    define("MAT_ALPHARAG_100_PERCENT_COTTON",1);
    define("MAT_ALPHARAG_ARTCARE",3);
    define("MAT_SELECT",44);
    define("MAT_PAPERMAT",66);
    
    class Mat 
    {
    
    public static $ConservationTypes = array (
    	MAT_ARCHIVAL => array ( ALPHARAG_100_PERCENT_COTTON,ALPHARAG_ARTCARE ),
    	MAT_CONSERVATION => array ( SELECT ),
    	MAT_DECORATIVE => array ( PAPERMAT )
    );
    
    public static $MatGroups = array (
    	ALPHARAG_100_PERCENT_COTTON => array ( "B8605","B8606","B8607","B8614"),
    	ALPHARAG_ARTCARE => array ( "B8634","B863412P","B8634L","B8640","B86408P","B8640L","B8641","B8642"),
    	SELECT => array ( "C89500","C89501","C89502","C89505","C89506","C89507","C89508","C89510","C89511"),
    	PAPERMAT => array ( "C1000","C1001","C1002","C1007","C1008","C1009","C1013","C1014","C1015",)
    );
    
    public static $Mat = array (
    	"B8605" => array ( "ffffff",MAT_32X40,8.17,"B8605",1,"White"),
    	"B8605" => array ( "ffffff",MAT_32X40,8.17,"B8605",1,"White"),
    	"B8606" => array ( "FFF4DA",MAT_32X40,8.17,"B8606",1,"Ivory"),
    	... more mats
    	"B8606" => array ( "FFF4DA",MAT_32X40,8.17,"B8606",1,"Ivory"),
    	"B8607" => array ( "ffffff",MAT_32X40,18.14,"B8607",1,"White"),
    	"B8607L" => array ( "ffffff",MAT_40X60,18.14,"B8607",1,"White")
    );
    public static function GetMatDescription ( $MatNo ) 
    {
    	if ( array_key_exists ( $MatNo, self::$Mat) )
    		return self::$Mat [ $MatNo ] [ 4 ];
    }
    
    }
    ?>

    Still a lot to do.

    For example, lines like

    return self::$Mat [ $MatNo ] [ 4 ];

    will be replaced with an appropriate define like

    return self::$Mat [ $MatNo ] [ COL_ DESCRIPTION ];
    • Thanks for the great responses. Points taken. I don't know as much as I should about the tradeoffs between database/code and will be doing more reading and benchmarking. Both articles are good and will get more thought. BTW, the second link is truncated. Here is the full link for those interested.

      http://en.wikipedia.org/wiki/Optimization_%28computer_science%29

      BTW, All the defines shown are generated from the names in the tables.

      The script changes

      Alphamat Artcare Specialties Tuscany

      to

      ALPHAMAT_ARTCARE_SPECIALITIES_TUSCANY

      Since the generated class hasn't been used yet, I didn't notice the 100% which is now 100 PERCENT. Good catch.

      Since I can't use an include inside a class I have now generated the entire class via a script. The data needs to remain in the database. I will be doing some benchmarking as I implement portions of the site that use the data. Some may be via the class, other directly depending on the benchmarking. The items generated within the class may change as it progresses. The article on Premature Optimization suggests that I may be going about it a$$-backwards. I will find out if they are right. In either case the affected code will be localized to a class method or function. BTW, the primary access to the data will be via AJAX.

      The database represents the know universe of mats and types for the manufacturers I use. Each type/mat has an IsActive flag in the record so when it comes time to decide on my final product set, I wil use the IsActive flag to set the offerred products. The product universe changes often with new types and items added and discontinued. Updating the database is far easier than via code.

      BTW, the site is mine so I will have to be the one to live with the decisions I make. CRON failures will have an impact. I mentioned running this via a cron job. More likely I will run the script manually whenever I make changes to the database. My most popular menu selections will be via cron daily. That one I will have to keep an eye on.

      • I am trying to us an include inside a class body but get a unexpected T_INCLUDE, expecting T_FUNCTION error when I do so.

        Here's what and why I am trying to do.

        1. This is for a framing website and the class is about the matting used for framing.

        2. The definitions and types of the mats used are in several mysql tables.

        3. There are over 80 types of mats with a number of attribute tables (sizes, manufacturer, conservation type, etc) and over 2600 mats.
          4, The 80 or so types will be used to populate drop down lists based on some of the other criteria (If the request archival mats, one list is shown, textured mats, another list, etc).

        4. These lists will be requested very often during a site visit.

        5. Generating them directly from mysql is going to be slower than I want.

        6. The mats and status (IsActive) will change often so I only want to have to change one source (the db)

        7. I need a static class to access the mats and their attributes, not just for the generation of the lists but for other purposes.

        8. The general structure of the class file will be

          <?php
          include_once( "MatLists.php" );   // created dynamically via a script
          
          class Mat
          {
          	include "MatArrays.php";   // also created dynamically via a script
          
          public static function GetMatDescription ( $MatNo ) 
          {
          	if ( array_key_exists ( $MatNo, self::$Mat) )
          		return self::$Mat [ $MatNo ] [ 4 ];
          }
          
          .... more access functions
          
          }
          ?>

          which when expanded will look like

          <?php
          define("MAT_ARCHIVAL",1);
          define("MAT_CONSERVATION",2);
          define("MAT_DECORATIVE",3);
          
          define("BAINBRIDGE",1);
          define("CRESECENT",2);
          
          define("MAT_4_PLY",4);
          define("MAT_8_PLY",8);
          define("MAT_12_PLY",12);
          
          define("MAT_32X40",1);
          define("MAT_40X60",2);
          
          define("MAT_ALPHARAG_100%_COTTON",1);
          define("MAT_ALPHARAG_NATURALS",2);
          define("MAT_ALPHARAG_ARTCARE",3);
          define("MAT_ALPHAMAT_ARTCARE_SOLIDS",4);
          define("MAT_ALPHAMAT_ARTCARE_SPECIALTIES_PRECIOUS_METALS",5);
          ... and more definitions
          class Mat
          {
          	public static $ConservationTypes = array {
          		MAT_ARCHIVAL => array { ALPHARAG_100%_COTTON,ALPHAMAT_ARTCARE_SPECIALTIES_HERITAGE,ALPHAMAT_ARTCARE_SPECIALTIES_TRACES,ALPHAMAT_ARTCARE_SPECIALTIES_AMERICAN_CLASSICS,ALPHAMAT_ARTCARE_SPECIALTIES_CLASSICOS,ALPHAMAT_ARTCARE_SPECIALTIES_PARCHMENTS,ALPHAMAT_ARTCARE_SPECIALTIES_ALPHA_LINENS,ALPHAMAT_ARTCARE_WASHED_LINEN,ALPHAMAT_ARTCARE_LEATHER,ALPHAMAT_ARTCARE_DENIMS,ALPHAMAT_ARTCARE_COLOR_CORE,ALPHAMAT_ARTCARE_NEW_THREADS,ALPHAMAT_ARTCARE_SUEDE,ALPHAMAT_ARTCARE_EMBOSSED_SUEDE,ALPHAMAT_ARTCARE_GRASSCLOTH,ALPHAMAT_ARTCARE_RICE_PAPER,ALPHAMAT_ARTCARE_METTALIC_RICE_PAPER,ALPHAMAT_ARTCARE_SILKENS,ALPHAMAT_ARTCARE_TATAMI_SILKENS,ALPHAMAT_ARTCARE_RAW_SILKS,RAGMAT_MUSEUM_SOLIDS,RAGMAT,RAGMAT_ANTIQUARIAN,RAGMAT_SPECIALTIES,RAGMAT_NOIR_BLACK_CORE,ELIZABETH_DOW_COLLECTION,MICHAEL_GRAVES_COLLECTION,RAGMAT_INTAGLIO},
          		MAT_CONSERVATION => array { SELECT,SELECT_ULTIBLACKS,ACCENTS,ULTIBLACK_FLORENTINES,SELECT_PALAZZOS,SELECT_BELGIQUES,SELECT_ULTIBLACK_BELGIQUES,MOORMAN_SUEDES,BLACK_CORE_MOORMAN_SUEDES,MOORMAN_NATURAL_LINENS,MOORMAN_LINENS,MOORMAN_LEATHER},
          		MAT_DECORATIVE => array { PEBBLE_PAPER_MATS,PAPER_MATS,PAPERMAT_FORMALS,PAPERMAT_FORMALS_BLACK_CORE,BLACK_BY_BAINBRIDGE_PAPERMAT,INTERNATION_WHITECORE,CRESCENT_INTERNATION_WHITECORE_FAUX_METALLIC,CRESCENT_INTERNATION_WHITECORE_FAUX_MARBLE,CRESCENT_INTERNATION_WHITECORE_FAUX_MARBLE_BLACK_CORE,INTERNATION_WHITECORE_CLASSICS_FAUX_LEATHER,INTERNATION_WHITECORE_CLASSICS_LIBRARY_LEATHER,PAPERMAT,BRITECORES_PAPERMAT,_FLANNEL_PAPERMAT,LINI_PAPERMAT,SILKI_PAPERMAT,PARCHMENT_PAPERMAT,CRESCENT_DENIM_PAPERMAT,NEOCLASSICS_PAPERMAT,PRECIOUS_METALS_PAPERMAT,ANCIENTS_PAPERMAT,FLORENTINE_METTALICS_PAPERMAT,BLACK_CORE_PRECIOUS_METALS_PAPERMAT,BLACK_CORE_PAPERMAT,BLACK_CORE_FLANNEL_PAPERMAT}
          	};
          
          public static $MatGroups = array {
          	ALPHARAG_100%_COTTON => array ( "B8605","B8606","B8607","B8614"},
          	ALPHARAG_NATURALS => array ( "B8626","B8627","B8628","B8629","B8689","B8690"},
          	...... more groups 80+ inall
          	BLACK_CORE_PRECIOUS_METALS_PAPERMAT => array ( "C63702","C63703","C63708","C63713"},
          	BLACK_CORE_FLANNEL_PAPERMAT => array ( "C63300","C63305","C63306","C63307","C63310","C63311"}
          };
          
          public static $Mat = array {
          	"B110" => array ( 1,3.43,"B110",1, "Off White & White Pebble"),
          	"B110L" => array ( 2,8.48,"B110L",1, "Off White & White Pebble"),
          	........   more mats - 2600 in all
          	"B4119L" => array ( 2,29.83,"B4119L",1, "Grappa"),
          	"B412" => array ( 1,3.92,"B412",1, "Tan"),
             );
          
          public static function GetMatDescription ( $MatNo ) 
          {
          	if ( array_key_exists ( $MatNo, self::$Mat) )
          		return self::$Mat [ $MatNo ] [ MAT_DESCRIPTION_COLUMN ];
          }
          ... more access functions
          }
          ?>

          Both of the include files are generated via a php script that will run daily via a cron job.The inclusion of first file MatLists.php, that includes defines generated from the db is not a problem as it is outside the class.

          The file that I wish to include inside the class is the problem. I can't find (a lot of googling seems to say it can't be done) a way to do this.

          I don't want to include the file outside the class. I prefer the structure of static class access as opposed to a bunch of global arrays.

          Plan A, if anyone can offer any suggestions, is figure out a way to overcome the include restrictions inside a class.

          Plan B, if I can't figure it out is to dynamically write the entire class, including all the functions dynamically.

          I use the same thing in other portions of the site. There will be over 200K products on the site. The menus are all dynamic (sortof) and will be structured by most the most popular viewed products (top artists, top subjects, top art styles, top items, etc). They menus are created via a daily cron jobs that creates top viewed lists from the hits tables, which are incremented anytime an item is viewed, which then define the menus. These are also in a static class which has only data, so I write the entire class dynamically for this one.

          Suggestions are welcome. Thanks in advance.

        • ImageJpeg() can send output directly to the browser or to a file. When sending directly to a browser, the image can be the only thing sent to the browser. Otherwise you will get the Warning: Cannot modify header information - headers already sent by (output started at... error.

          I need to display the output of ImageJPEG as part of a page along with other content, not just the only thing on the page. I could write it to a file, but don't want to use this extra step unless I can't find any alternative.

          Is there anyway to send the image to the browser along with other normal content?

          • I have several domains hosted on an Apache 2.0.55, PHP 4.3.11, MySQL 3.23.58 VPS. All sites use the same IP. Much of the code for the sites is shared in a common directory using the Apache Alias directive.

            Among the common code is a shopping cart and checkout that I wrote that all the sites use. Currently the sites are not secure. Payment is made after checkout via paypal or calling in a credit card. I want to add online processing of credit cards to my checkout and make it secure.

            My problem is that I only want to buy one SSL certificate, rather than one for each site.

            Currently when when something is added to the cart or goes to checkout, the URLS the customer goes to is something like:

            http://www.thePaperFramer.Com/AddToCart.php
            http://www.ComicFrames.Com/AddToCart.php
            http://www.thePaperFramer.Com/Checkout.php
            http://www.ComicFrames.Com/Checkout.php
            etc

            The AddToCart.php and Checkout.php scripts are shared across all domains. I want all checkout to now go through https://www.thePaperFramer.Com/Checkout.php using a single SSL certificate for thePaperFramer.Com. The cart itself will continue to be shared as is presently.

            Most of this is straightforward but I have one issue that I can't decide on how to implement. That is moving the cart data from any of the domains to the checkout URL.

            The cart data is stored in a session array. I can't decide what is the best way to move the cart data from the originating domain to the checkout domain. There appears to be several ways that this might be done.

            1. I could POST all the cart data when I call the checkout URL. I don't know what the maximum size might be. Places like Yahoo stores seem to use this method for their shared carts and checkout. This method doesn't really appeal to me.

            2. I could write the session cart array to a cookie but I haven't found a way yet of accessing a cookie from another domain.

            3. If I could share the session data accross domains, this might work but I haven't found a way to do this yet.

            4. I could write the cart to a database table. This is complicated slightly because the some of the domains use a different database.

            I have googled this around and searcha number of furoms, but haven't seen a good solution for this. Any suggestions on the best way to proceed?

            • I think I have it now. When you do:

              $_SESSION [ 'st' ] = $st;

              php makes a byte COPY of $st and places it in the $SESSION variable. anything done to the local copy of $st doesn't affect the $SESSION version of it. Coming from C++, I had assumed (wrongly) that it created an reference, not a copy.

              So instead of the code I had:

              $st->SetID ( 2 ); // changes local copy only

              I should have had

              $SESSION [ 'st' ]->SetID ( 2 ); // changes $SESSION copy but not local copy

              or

              $s = $SESSION [ 'st' ];
              $s->SetID(2); // changes $
              SESSION copy but not local copy

              The moral is not to use the local copy after it is copied to a $_SESSION variable

              Thanks

              • A simplifed code snipped of a problem thats driving me crazy is below. I have created a class, initialized it in the constructor and save an instance of the class in a $_SESSION variable. The ID variable is initialized in the constructor to 1. I can retrieve the class data fine but I can't change it. In the snippet below I call a class function to change the ID variable to 2 and it shows it changing fine, but when I list the contents of the $SESSION variable it shows it not being changed. Further, if I list the object contents using the class intstance that was returned, it shows the ID with the changed value of 2.

                I can't figure this out. Am I making some kind of newbie error. It seems like I have two instances of the class. I have shown the code, output and the session portion of phpinfo(); My php version is 4.3.8 on XP Pro.

                Code


                <?php
                session_start();
                class Store
                {
                	var $ZipCode;
                	var $ID;
                
                function Store() 
                {
                	$this->ZipCode     = "99999";
                	$this->ID = 1;
                }
                function SetID( $ID ) 
                {
                	$this->ID = $ID;
                	echo "<br>Set ID in Class = ";
                	echo $this->ID;
                }
                function ShowID( ) 
                {	
                	echo "<br>Show ID = in Class = ";
                	echo $this->ID;
                }
                }
                function print_vars($obj) 
                {
                    $arr = get_object_vars($obj);
                    while (list($prop, $val) = each($arr))
                        echo "\t$prop = $val\n";
                	echo "<br>";
                
                }
                function  ShowSessionVariables ( )
                {
                    echo "<br>******_SESSION*****************<br>";
                    while(list($key, $value) = each($_SESSION)) 
                    { 
                        echo "$key = $value<br>"; 
                		print_vars ( $value );
                    }
                	reset ( $_SESSION );
                }
                
                $st = new Store();
                echo "After Constructor";
                $_SESSION [ 'st' ] = $st;
                ShowSessionVariables ( );
                echo "Print Vars";
                print_vars ( $st );
                
                
                $st->SetID ( 2 );
                echo "<br>After Changing ID ";
                ShowSessionVariables ( );
                echo "Print Vars";
                print_vars ( $st );
                echo $st->ID;
                echo $st->ShowID();
                ShowSessionVariables ( );
                ?>
                

                OUTPUT with comments

                After Constructor
                ***_SESSION**************
                st = Object
                ZipCode = 99999 ID = 1
                Print Vars ZipCode = 99999 ID = 1
                // All fine to this point

                // Set ID to 2
                Set ID in Class = 2
                After Changing ID
                ***SESSION***********
                st = Object
                ZipCode = 99999 ID = 1 // Session vars still show it as 1
                Print Vars ZipCode = 99999 ID = 2 Print vars show it changed
                2

                Show ID = in Class = 2 Call to class function show it changed
                SESSION**************
                st = Object
                ZipCode = 99999 ID = 1 // $SESSION variable not changed

                php.ini variables

                Session Support enabled

                Registered save handlers files user

                Directive Local Value Master Value
                session.auto_start Off Off
                session.bug_compat_42 On On
                session.bug_compat_warn On On
                session.cache_expire 180 180
                session.cache_limiter nocache nocache
                session.cookie_domain no value no value
                session.cookie_lifetime 0 0
                session.cookie_path / /
                session.cookie_secure Off Off
                session.entropy_file no value no value
                session.entropy_length 0 0
                session.gc_divisor 100 100
                session.gc_maxlifetime 1440 1440
                session.gc_probability 1 1
                session.name PHPSESSID PHPSESSID
                session.referer_check no value no value
                session.save_handler files files
                session.save_path /tmp /tmp
                session.serialize_handler php php
                session.use_cookies On On
                session.use_only_cookies Off Off
                session.use_trans_sid Off Off😕 😕

                • My sites, MagazineFrames.Com and ComicFrames.com have been working merrily for several months. Until today. I got an email from a buyer saying that he couldn't complete an order. When he went to view his cart he got a message saying there was nothing in his cart. I can't sell much that way. Checking into it I discovered that other things such as my admin pages that rely on session variables wern't working either. None of my session variables were working for anything.

                  After much testing, debugging, looking at all my php params and restarting the server a couple of times, I discovered that all the session files were being written with zero length. No disk space left even though my ISP's reports showed that I had 150 meg left out of 500. After cleaning out some log files I was back in business. My ISP has been promising some log file tools for the last couple of months and I had been waiting on them. No more waiting. I have root access so tonight I start my working on my own scripts for log file cleanup.

                  I add this for future searches in case anyone else happens to be as dumb as I and ignores their log files.

                  • I have a web site implemented in php 4.x and MySQL 3.22.x running on linux and have local test sites running on W2K and linux. As an exercise, I have implemented a database wrapper for MySQL, MSSQL Server 2000 and Orcacle9i and will be adding one for Sybase shortly.

                    I have a question on the Oracle implementation with code fragments below to illustrate. In MySQL and SQL Server I can retrieve data from a row by Column Name. So far I haven't been able to get that to work. In the code below I can retrieve the 'Count' column by $Count = $QueryData [ "Count" ]; but for Oracle that doesn't work and I have to use $Count = $QueryData [ 0 ];. Calling ora_fetch_into using the ORA_FETCHINTO_ASSOC
                    flag doesn't work. When I use it, I can't even retrieve the column value by number.

                    Does anyone have any suggestions why the ORA_FETCHINTO_ASSOC flag doesn't work or how to retrieve column data by Column Name.

                    function GetPageCount ( $MiddlePanelFile )
                    {
                        global $Server;
                    
                    // Open the DB
                    $link = ConnectToDatabase ( );
                    
                    // Get the count for the page
                    $query = "select Count from PAGECOUNTS where PageName = '$MiddlePanelFile' and Server = '$Server'";
                    $result = dbQuery ( array ( $query, $link ) );
                    
                    if ( !$result ) 
                        return false;
                    else
                    {   
                        if ( DB_ORACLE9i ) 
                        {
                            array ( $rows );
                            $QueryData = dbFetchRow ( array ( $link, $rows ) );                        // Works
                            //$QueryData = dbFetchRow ( array ( $link, $rows, DB_GETMODE_ASSOC ) );    // Doesn't Work
                            //$QueryData = dbFetchRow ( array ( $link, $rows, DB_GETMODE_NULL ) );     // Works
                            $Count = $QueryData [ 0 ];
                        }
                        else
                        {
                            // MySQL and SQL Server 2000
                            $QueryData = dbFetchRow ( array ( $result, DB_GETMODE_BOTH ) );
                            $Count = $QueryData [ "Count" ];
                        }
                    
                        if ( $Count )
                        {
                            // add one to the page count
                            $query = "update PAGECOUNTS set Count = Count + 1 where PageName = '$MiddlePanelFile' and Server = '$Server'";
                            $result = dbQuery ( array ( $query, $link ) );
                            $Count++;
                        }
                        else 
                        {
                            // record doesn't exist, add it
                            $query = "insert into PAGECOUNTS VALUES ( '$MiddlePanelFile', '$Server', 1051 )";
                            $result = dbQuery ( array ( $query, $link ) );
                            $Count = 1051;
                        }
                    }
                    return $Count;
                    }
                    // Oracle9i dbFetchRow
                    function dbFetchRow ( $args = array ( ) ) 
                    {
                        switch ( $args [ 2 ] )
                        {
                            case DB_GETMODE_ASSOC:
                                $cols = @ora_fetch_into ( $args [ 0 ], $rows, ORA_FETCHINTO_ASSOC );
                                break;
                            case DB_GETMODE_NULL:
                                $cols = @ora_fetch_into ( $args [ 0 ], $rows, ORA_FETCHINTO_NULLS );
                                break;
                            default:
                                $cols = @ora_fetch_into ( $args [ 0 ], $rows );
                                break;
                        }
                        if ( $cols )
                            return $rows;
                        return false;
                    }
                    // MySQL FetchRow
                    function dbFetchRow ( $args = array ( ) ) 
                    {
                        if ( $args [ 1 ] == DB_GETMODE_ASSOC ) 
                        {
                            @mysql_fetch_array ( $args [ 0 ], MYSQL_ASSOC );
                        }
                        elseif ( $args [ 1 ] == DB_GETMODE_NUM ) 
                        {
                            return @mysql_fetch_array ( $args [ 0 ], MYSQL_NUM );
                        }
                        return @mysql_fetch_array ( $args [ 0 ] );   // MYSQL_BOTH
                    }
                    // SQL Server 2000 dbFetchRow
                    function dbFetchRow ( $args = array ( ) ) 
                    {
                        return @mssql_fetch_array ( $args [ 0 ] );   
                    }
                    • I have two sites running as vhosts (one up MagazineFrames.Com, one under development, ComicFrames.Com) using apache 1.3.20, php 4.0.1 and mysql 3.22.32. These two sites will share about 50% of their code and content as well as using the same database tables and home grown cart.

                      MagazineFrames.Com (MFC) is for custom framing of collectible pinup magazines such as Playboy and others and has about 400 covers from the 1920s-1970s and is 'R' rated. ComicFrames.Com (CFC)is for custom framing of comics and will be 'G' rated. I want to keep the sites seperate because some venues (Paypal shops for one rejected MFC because the Playboy covers violated their community standards) don't allow 'R' rated sites.

                      I would like to share session data between the two sites so that a user could move between the sites at will and purchase from both in a session. While not extrememly important, I haven't found a way to do this yet and currently of the opinion that it isn't allowed easily. Of course I would like to be wrong, so hence, this post.

                      Does anyone know of a way to do this? I will have links between the two sites and would like a user to be able to add to the same cart from both (I save all my cart data as session variables) and checkout from both all at once.

                      Thanks

                      • You seem to be missing the mysql_fetch_row() after you do your last mysql_query(). Here is a function of mine that does somthing similiar to what you want. It adds a Record to the CUSTOMERS table and returns the CustomerID of the Customer added.

                        function AddCustomerToDB ( )
                        {
                        $t = $GLOBALS;
                        // Open the DB
                        $link = ConnectToDatabase ( );

                        $query = "insert into CUSTOMERS VALUES ( 
                                    NULL, 
                                    '{$t[ 'EMailAddress' ]}', 
                                    '{$t[ 'BillingFirstName' ]}', 
                                    ....   // more columns here left out
                                    '{$t[ 'ShippingZip' ]}' 
                                 )";
                        $result = mysql_query ( $query, $link );
                        if ( !$result )
                            return false;
                        
                        $query = "select CustomerID from CUSTOMERS where EMailAddress = '{$t[ 'EMailAddress' ]}'"; 
                        $result = mysql_query ( $query, $link );
                        
                        if ( !$result )
                            return false;
                        else
                        {   
                            // record exists, get it 
                            $QueryData = mysql_fetch_row ( $result );
                            $CustomerID = $QueryData [ 0 ];
                        }
                        return $CustomerID;

                        }

                        • I just finished building a small shopping cart for a site and took a brief look at most of what's out there. A goggle search on 'php shopping carts' will put your brain into overload.

                          I ended up basing parts of mine on the shopping cart example in the book 'PHP and MySQL Web Development' by Welling and Thomson and adding what I needed. Their example was clear enough that I don't think I even read the chapter that went with it.

                          In mine I did things like pricing shipping based on a a cost for the first and lesser costs for additional items and discounts based on order total. Once you take a look the the various pieces in a simple example like this book has, it may all fall in place easier.

                          Some of the available carts try to be all things to all sites and end up having too much code for what most of us need.

                          Your requirements should be easy to meet once you have a working example to draw from. Recognizing tax exempt should be as easy as an if( !strlen ($TaxExempt) ) {...}that skips the sales tax calculation when they enter a valid (I don't know how you would validate a tax exempt number for your state) tax exempt number. For the shipping, you would calculate it based on a weight that is in the db record for the item being purchased.

                          • I agree with both of the above. I'm just finishing a new site that is 100% php and mysql. I did the development on W2K, apache, php 4.1.x and mysql. The production version is linux, apache, php 4.0.x and mysql. I didn't have a single problem between W2K and linux.

                            My only additional comment is that ASP and Perl are a bit more mature. I would like to see some more progression in php such as the LWP library for Perl or the new .NET form controls. I'm sure that php will get there but the others have been around a bit longer (or have more MS resources to throw at it).

                            • One of the biggest uses of custom session handlers is where you are running a web farm and have multiple servers handling requests. You would need to keep session information in a db (or as hidden variables in a post from each page) since each request might go to a different sever in a farm.

                              If you aren't running a farm (web) and don't have any special requirements, then php sessions should serve you well.

                              • A couple of things may be causing your problem. The line

                                <input type="text name="test">

                                Should be

                                <input type="text" name="test">

                                Also you are using the name test for both the form and one of the fields. Try renaming one.

                                Also you can look at the HTTP_POST_VARS

                                reset($HTTP_POST_VARS);
                                while(list($key, $value) = each($HTTP_POST_VARS))
                                {
                                echo "$key = $value<br>";
                                }

                                to make sure that $test is being received.

                                • While you are debuggin you might want to use this functions to see all you global variables.

                                  function ShowGlobalVariables ( )
                                  {
                                  global $HTTP_POST_VARS,
                                  $HTTP_GET_VARS,
                                  $HTTP_ENV_VARS,
                                  $HTTP_COOKIE_VARS,
                                  $HTTP_SERVER_VARS,
                                  $HTTP_SESSION_VARS;

                                  echo "******HTTP_POST_VARS*****************<br>";
                                  reset($HTTP_POST_VARS);
                                  while(list($key, $value) = each($HTTP_POST_VARS)) 
                                  { 
                                      echo "$key = $value<br>"; 
                                  }
                                  
                                  echo "******HTTP_GET_VARS*****************<br>";
                                  reset($HTTP_GET_VARS);
                                  while(list($key, $value) = each($HTTP_GET_VARS)) 
                                  { 
                                      echo "$key = $value<br>"; 
                                  }
                                  
                                  echo "******HTTP_SESSION_VARS*****************<br>";
                                  reset($HTTP_SESSION_VARS);
                                  while(list($key, $value) = each($HTTP_SESSION_VARS)) 
                                  { 
                                      echo "$key = $value<br>"; 
                                  }
                                  
                                  echo "******HTTP_ENV_VARS*****************<br>";
                                  reset($HTTP_ENV_VARS);
                                  while(list($key, $value) = each($HTTP_ENV_VARS)) 
                                  { 
                                      echo "$key = $value<br>"; 
                                  }
                                  
                                  echo "******HTTP_COOKIE_VARS*****************<br>";
                                  reset($HTTP_COOKIE_VARS);
                                  while(list($key, $value) = each($HTTP_COOKIE_VARS)) 
                                  { 
                                      echo "$key = $value<br>"; 
                                  }
                                  
                                  echo "******HTTP_SERVER_VARS*****************<br>";
                                  reset($HTTP_SERVER_VARS);
                                  while(list($key, $value) = each($HTTP_SERVER_VARS)) 
                                  { 
                                      echo "$key = $value<br>"; 
                                  }
                                  
                                  echo "******GLOBALS*****************<br>";
                                  foreach ($GLOBALS as $key => $element)
                                      echo "$key  $element<br>\n"; 

                                  }

                                  • For a site I'm doing that allows paypal payments I need to respond to a POST from paypal, rePOST back to them adding a reponse code and then check their response for validity. Paypal has supplied a sample Perl script to do this but I would rather hadnle this in PHP (especially the database updates) since the rest of the site is in PHP (and since I haven't used Perl that much).

                                    The sample Perl script is as follows;

                                    #!/usr/local/bin/perl
                                    #read the post from PayPal system and add 'cmd'
                                    read (STDIN, $query, $ENV'CONTENT_LENGTH'}); $query .= '&cmd=_notify-validate';

                                    post back to PayPal system to validate

                                    use LWP::UserAgent;
                                    $ua = new LWP::UserAgent;
                                    $req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr'; $req->content_type('application/x-www-form-urlencoded');
                                    $req->content($query);
                                    $res = $ua->request($req);

                                    split posted variables into pairs

                                    @pairs = split(/&/, $query);
                                    $count = 0;
                                    foreach $pair (@pairs) {
                                    ($name, $value) = split(/=/, $pair);
                                    $value =~ tr/+/ /;
                                    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
                                    $variable{$name} = $value;
                                    $count++; }

                                    assign posted variables to local variables $receiver_email = $variable{'receiver_email'};

                                    $item_name = $variable{'item_name'}; $item_number = $variable{'item_number'}; $custom = $variable{'custom'}; $payment_status=$variable 'payment_status'};
                                    ....
                                    $payer_email = $variable{'payer_email'};

                                    if ($res->content eq 'VERIFIED') {

                                    check transaction for uniqueness

                                    process payment }

                                    elsif ($res->content eq 'INVALID') {

                                    possible fraud }

                                    else { # error}

                                    Most of the script is straight forward and can be done in PHP. I know that I can use fsockopen() to do the respond to the POST, but I can't figure out how to check the response ($res->content). My only thoughts right now is to use this script and to rePOST back to a PHP page from this script after the script checks for 'VERIFIED' or 'INVALID'.

                                    Does anyone have thoughts on this.
                                    Thanks,
                                    Larry

                                    • If you are using sessions, you can use the session_register() function to do this.

                                      1.php

                                      <?php
                                      session_start();
                                      session_register($var1);
                                      $var1=1234;
                                      ?>

                                      2.php

                                      <?php
                                      session_start();
                                      global $var1;
                                      echo $var1;
                                      ?>

                                      To look at your globals you might use this function of mine.

                                      function ShowGlobalVariables ( )
                                      {
                                      global $HTTP_POST_VARS,
                                      $HTTP_GET_VARS,
                                      $HTTP_ENV_VARS,
                                      $HTTP_COOKIE_VARS,
                                      $HTTP_SERVER_VARS,
                                      $HTTP_SESSION_VARS;

                                      echo "******HTTP_POST_VARS*****************<br>";
                                      reset($HTTP_POST_VARS);
                                      while(list($key, $value) = each($HTTP_POST_VARS)) 
                                      { 
                                          echo "$key = $value<br>"; 
                                      }
                                      
                                      echo "******HTTP_GET_VARS*****************<br>";
                                      reset($HTTP_GET_VARS);
                                      while(list($key, $value) = each($HTTP_GET_VARS)) 
                                      { 
                                          echo "$key = $value<br>"; 
                                      }
                                      
                                      echo "******HTTP_SESSION_VARS*****************<br>";
                                      reset($HTTP_SESSION_VARS);
                                      while(list($key, $value) = each($HTTP_SESSION_VARS)) 
                                      { 
                                          echo "$key = $value<br>"; 
                                      }
                                      
                                      echo "******HTTP_ENV_VARS*****************<br>";
                                      reset($HTTP_ENV_VARS);
                                      while(list($key, $value) = each($HTTP_ENV_VARS)) 
                                      { 
                                          echo "$key = $value<br>"; 
                                      }
                                      
                                      echo "******HTTP_COOKIE_VARS*****************<br>";
                                      reset($HTTP_COOKIE_VARS);
                                      while(list($key, $value) = each($HTTP_COOKIE_VARS)) 
                                      { 
                                          echo "$key = $value<br>"; 
                                      }
                                      
                                      echo "******HTTP_SERVER_VARS*****************<br>";
                                      reset($HTTP_SERVER_VARS);
                                      while(list($key, $value) = each($HTTP_SERVER_VARS)) 
                                      { 
                                          echo "$key = $value<br>"; 
                                      }
                                      
                                      echo "******GLOBALS*****************<br>";
                                      foreach ($GLOBALS as $key => $element)
                                          echo "$key  $element<br>\n"; 

                                      }

                                      • I am writing code to read and respond to Paypal's IPN (Instant Payment Notification) system. They are POSTing to my url and I need to POST back to them all their form variables EXACTLY as receieved plus add an acceptance variable to confirm reception.

                                        There are 23 form variables that they send along with their values. I know that I can loop through all the POST variables like the following:

                                        echo "******HTTP_POST_VARS*****************<br>";
                                        reset($HTTP_POST_VARS);
                                        while(list($key, $value) = each($HTTP_POST_VARS)) 
                                        { 
                                            echo "$key = $value<br>"; 
                                        }

                                        but I would prefer not to use this if it can be read as a block.

                                        In Perl I could do the following:

                                        read (STDIN, $query, $ENV{'CONTENT_LENGTH'});

                                        Is there something similiar in PHP?

                                        • For some reason all the pages I generate with PHP have 3 CRLF pairs (blank lines)at the start of the page. This doesn't seem to cause problems with normal HTML pages (except that you can see three blank lines in the page source) but my image pages no longer work because of this and I could'nt figure out where these CRLFs are coming from. I spent about a day working on this.

                                          I found the problem and am posting this because I didn't find anything about this in a forum search and want to share this so others won't have to go through this.

                                          The problem was cause by caused by having 3 blank lines at the end of a PHP include file after the final '?>' in the file. I'm not sure why PHP added these lines to the start of the output rather than in place where the file was included but others may encounter this problem.