page url problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    page url problem

    hii guys !!

    I have a website where in i was listing all the mobiles in a page like

    1.nokia 3310
    2.motorola p150
    3. ..

    so each mobile has description page . so i was passing the model(3310) and brand(nokia) in url to a page (mobile_desc,ph p) where i was getting the $_GET variables and querying it .

    1. now client wants some changes like the model and brand should not go through url, so how do i need to pass the model and brand to next page so that i can use it .

    2. and he wants pages like http://xyz.com/nokia3310 and stuff instead of http://xyz.com/mobile_desc.php so that google can recognize it .
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    1. $_POST variable? $_SESSION variable? $_POST for forms, but I would look into $_SESSION and maybe some AJAX to store it in the session when a user clicks something.
    2. The most common way is using .htaccess mod_rewrite, but you will need to think of how your real URL relates to what you want it to look like.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      say i take them in a form and list them .but whn i click on nokia 3110 how will $_POST in next page know that the nokia 3110 was clicked? i had this doubt only!

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        You can submit a form using Javascript and onChange or onClick.

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #5
          i think you got ma point wrong!


          i am like displaying a list of all mobiles in a page . like 10-20 mobiles with pictures of the mobile . when the user clicks on the picture of the mobile it takes him to description of the mobile . i was making the url of the image to next page like this in a while loop of a mysql query

          Code:
          $myresult .= "<a href='camera_rating.php?p1=". $row['property1'] . "&p2=".$row['property2'] . "'><img src='/camera/camerapicdisplay.php?p1=". $row['property1'] . "&p2=".$row['property2'] . "'</img></a>";
          where in i used to pass the needed data to next page .since GET is not best method to use . i wanted to pass it invisible to camera_rating.p hp .

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            I don’t see what should be wrong with GET, otherwise you have to make it a form to use POST.

            it will be especially a problem with the image url, because that’s not meant to be POSTed.

            Comment

            • pradeepjain
              Contributor
              • Jul 2007
              • 563

              #7
              okie !! if i continue with GET ! what are the ways so that i can mask the variables and values from users!!

              Comment

              • pradeepjain
                Contributor
                • Jul 2007
                • 563

                #8
                2. The most common way is using .htaccess mod_rewrite, but you will need to think of how your real URL relates to what you want it to look like.

                yeah as i said earlier instead of url like

                Code:
                http://xyz.com/camera_rating.php?p1=nokia&p2=3310
                it should look like

                Code:
                http://xyz.com/nokia3310

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  this looks like a job for mod_rewrite (if you are on Apache)

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    In your models database, allow for a field 'model_alias', or something like that. This field should correspond to what you want to display in the URL. So for your Brand: Nokia, Model: 3310 row, insert the alias: nokia3310. This is done because, without some extra processing, you wouldn't know what nokia3310 points to in the database.

                    Then use a simple rewrite such as:
                    Code:
                    RewriteEngine On
                    RewriteRule ^/phone/(.*)$ /phone?alias=$1
                    You then have access to the alias via $_GET['alias']. You can then use this data to pull the relevant information from the database.

                    Comment

                    • pradeepjain
                      Contributor
                      • Jul 2007
                      • 563

                      #11
                      okie i got the concept very well ! i will store the nokia3310 in ma table .

                      since the proj i am working has come a long way is it possible to ,maintain the url like

                      .xyz is for every website, everywhere.® We offer the most flexible and affordable domain names to create choice for the next generation of internet users.


                      and rewrite it to http://xyz.com/nokia3310

                      and i am on apache itself . i donot know much about rewrite

                      can you please tell what this piece of code is doing ?
                      Code:
                       RewriteRule ^/phone/(.*)$ /phone?alias=$1

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        converting /phone/xyz to /phone?alias=xyz

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          Originally posted by pradeepjain
                          okie i got the concept very well ! i will store the nokia3310 in ma table .

                          since the proj i am working has come a long way is it possible to ,maintain the url like

                          .xyz is for every website, everywhere.® We offer the most flexible and affordable domain names to create choice for the next generation of internet users.


                          and rewrite it to http://xyz.com/nokia3310
                          The difficulty with this is on what criteria do you process 'nokia3310'. Of course you could say split the letters from the numbers and then use that, which would be the equivalent of ^([a-zA-Z]+)([0-9]+) - or something like that. This however does not bode well for maintenance; what if you have a phone that has numbers in it's name, or a brand that has letters in it's model?

                          You could then say have a specific rule for each model & brand, the equivalent of RewriteRule ^/phone/nokia3310$ /mobile_rating.p hp?p1=nokia&p2= 3310 - of course there would be many more for each model & brand. But then when a new model or brand is created you would have to add this to the .htaccess file. The same goes for when you edit or delete a model or brand. I think you can see how this method is simply not viable.

                          There is another way using htaccess that you can perform a lookup using a RewriteMap, although I am not sure how quick (read: slow) this method is.

                          After considering the above options, I think you can see why I suggested using an alias as it drastically cuts down the work needed in maintenance and extensibility, etc. That said, however, you have to decide whether using an alias would require a rewrite of the existing code and whether that rewrite would be more expensive than one of the aforementioned methods.

                          - Mark.

                          P.S. There may be other methods that I have overlooked.

                          Comment

                          • Markus
                            Recognized Expert Expert
                            • Jun 2007
                            • 6092

                            #14
                            Originally posted by pradeepjain
                            can you please tell what this piece of code is doing ?
                            Code:
                             RewriteRule ^/phone/(.*)$ /phone?alias=$1
                            See the documentation on mod_rewrite, more specifically the RewriteRule directive.

                            Comment

                            • pradeepjain
                              Contributor
                              • Jul 2007
                              • 563

                              #15
                              okie i make the url look like

                              Code:
                              http://xyz.com/mobile_rating.php?nokia3310
                              can it be rewritten to without mobile_rating.p hp and all ?

                              Code:
                              and rewrite it to http://xyz.com/nokia3310

                              Comment

                              Working...