Need PHP basic help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • the indigo
    Confirmed User
    • Sep 2001
    • 2016

    #1

    Need PHP basic help

    Okay, pretty simple stuff but I'm not able to find out wtf doesn't work.

    I need the "rid" from http://www.blah.com/gallery.php?rid=2000 to be added to each sponsor link. ie:

    http://www.blah.com/gallery.php?rid=2000
    goes to
    http://www.sponsor.com/tour.php?rid=2000

    And if I type a different "rid", it will automatically modify all the links.

    Currently, all pages are in .php and links look like this: http://www.sponsor.com/tour.php?rid=

    I'm sure I have something to add in the header in php. thanks!
    "There he goes. One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die." -Hunter S. Thompson
  • TonyL
    Confirmed User
    • Feb 2002
    • 900

    #2
    If I understand your need correctly this should work:

    PHP Code:
    http://www.sponsor.com/tour.php?rid=<?echo $rid;?>

    -Tony
    Last edited by TonyL; 11-18-2003, 04:59 PM.

    Comment

    • richard
      Confirmed User
      • Feb 2001
      • 543

      #3
      Noob!

      PHP Code:
      <?php
      $rid = $_GET['rid'];
      $url = "http://www.sponsor.com?rid=" . $rid;
      echo "<a href=\"$url\">click me<a/>";
      ?>

      Comment

      • hornycash
        Confirmed User
        • Jun 2002
        • 2336

        #4
        PHP Code:
        <? echo "$rid"; ?>

        Comment

        • the indigo
          Confirmed User
          • Sep 2001
          • 2016

          #5
          great, thanks guys
          "There he goes. One of God's own prototypes. A high-powered mutant of some kind never even considered for mass production. Too weird to live, and too rare to die." -Hunter S. Thompson

          Comment

          • Zer0
            Registered User
            • Aug 2003
            • 16

            #6
            Another longer way to do it (which could have issues if your linking elsewhere off your site), but it would save time adding the code to each link... is just to get the page to open the original file as an input and go a preg_replace for all link tags adding ?rid=$rid to the end of the link values. Sure this is the longer way around and the page might load slightly slower, but hell I'm lazy and I don't want to spend the 3 secs it takes to do a search/replace on a page of code :P

            Plus you ever seen the face of a graphic designer when they see "funny" code. They stop in their tracks with this strange look, then it... "what do I do with this"...

            Comment

            • Script Dude
              Registered User
              • Jun 2002
              • 86

              #7
              Save the following to a file called fixlinks.php:
              PHP Code:
              <?php 
              function FixLinks($buffer) {
                  return isset($_GET['rid']) ? 
                      str_replace('rid=1000', 'rid=' . $_GET['rid'], $buffer) : $buffer;
              }
              
              ob_start("FixLinks");
              ?>
              Now once at the top of each of your gallery.php files put:
              PHP Code:
              <?php include 'fixlinks.php'; ?>
              This will change all the links on the page of the form

              http://www.sponsor.com/tour.php?rid=1000

              rid=1000 is your default code if someone forgets to add an rid= parameter to the url or it gets lost.

              Works on PHP 4.1 or later.

              Alternatively, in your .htaccess file put
              PHP Code:
              <Files ~ "\.php$">
              php_value auto_prepend_file "fixlinks.php"
              </Files> 
              
              And all PHP files in that directory will automagically have their links redone and you don't have to change them in any way.

              PHP Code:
              <Files ~ "\.html$">
              php_value auto_prepend_file "fixlinks.php"
              ForceType application/x-httpd-php 
              </Files> 
              
              With this all the html files in the directory will become PHP files and have their links rewritten.

              I haven't tested any of this. You'll be lucky if it works.

              Damn, the PHP highlighting colors are fugly on this board. and vBulleton mangles code. There is a \ in front of the .php and in front of .html in the .htacces file samples. you really will be lucky to get this to work.

              Comment

              • hibbidiji
                Confirmed User
                • Sep 2002
                • 208

                #8
                jesus what a fucking mess... man. if you want to do it.. in most cases the very first reply will work fine. If it DOESNT work, use the second one.. if you want to get confused and more than you wanted to deal with, try the other suggestions. Thing is, that the first one is the most tedious to code, but is most flexible. The second one will make it so that EVERY coded link on the page will go to the same place (defined by $url) not necessarily bad, but just not quite as flexible as doing it all by hand.

                D
                ---------------

                Comment

                • Zer0
                  Registered User
                  • Aug 2003
                  • 16

                  #9
                  yeah agreed that the first is the simplest, but thin of the pain when it comes to adding that code to each link and you have a front end with the main graphic split into 40~50+ linked images... aaah the pain :P

                  But yeah, do it which ever way, it gets you the same result in the end.

                  Comment

                  • Dugan
                    Confirmed User
                    • Nov 2003
                    • 856

                    #10
                    how come scripting always comes in so small?
                    specifically php

                    Comment

                    • hibbidiji
                      Confirmed User
                      • Sep 2002
                      • 208

                      #11
                      Originally posted by Zer0
                      yeah agreed that the first is the simplest, but thin of the pain when it comes to adding that code to each link and you have a front end with the main graphic split into 40~50+ linked images... aaah the pain :P

                      But yeah, do it which ever way, it gets you the same result in the end.
                      lol. finally sound thinking we just have to remember that unless someone wants to get into scripting, its easier to learn little things one at a time. echo is fast and easy to understand... by the time we're doing regexp and shit its too much to learn at once and still get shit done. I would probably write a freaking admin to manage all the links through php+mysql with a custom apache mod to replace app my links.. it would take 5 hours to write and would save 20 minutes but thats what we programmers do hehe
                      ---------------

                      Comment

                      • JDog
                        Confirmed User
                        • Feb 2003
                        • 7453

                        #12
                        Originally posted by hibbidiji


                        lol. finally sound thinking we just have to remember that unless someone wants to get into scripting, its easier to learn little things one at a time. echo is fast and easy to understand... by the time we're doing regexp and shit its too much to learn at once and still get shit done. I would probably write a freaking admin to manage all the links through php+mysql with a custom apache mod to replace app my links.. it would take 5 hours to write and would save 20 minutes but thats what we programmers do hehe
                        hehe I hear ya there! And I also agree that the first one is the easy one to do, and there is no use in preg_replace unless you're deciding about chinging links

                        jDoG
                        NSCash now powering ReelProfits.com
                        ALSO FEATURING: NSCash.com :: SoloDollars.com :: ReelProfits.com :: BiminiBucks.com :: VOD
                        PROGRAMS COMING SOON: Greedy Bucks :: Vengeance Cash
                        NOW OFFERING OVER 60 SITES
                        CONTACT :: JAMES SMITH :: CHIEF TECHNOLOGY OFFICER :: ICQ (711385133)

                        Comment

                        • Script Dude
                          Registered User
                          • Jun 2002
                          • 86

                          #13
                          Originally posted by TonyL
                          PHP Code:
                          http://www.sponsor.com/tour.php?rid=<?echo $rid;?>
                          If you want to do it this way and you have PHP 4.2 or better, this probably won't work.

                          This will work on PHP 4.1 or better:

                          PHP Code:
                          http://www.sponsor.com/tour.php?rid=<?echo $_GET['rid'];?>

                          Comment

                          Working...