PHP Question = Keeping a Variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkx
    Confirmed User
    • Nov 2003
    • 4001

    #1

    PHP Question = Keeping a Variable

    Quick question, I am trying to make it so that a variable is kept even when the user clicks to another page. For example:

    They go to www.yahoo.com?ref=55

    and then from yahoo they click news. I want it to then go to:

    www.yahoo.com/news?ref55

    instead of just going to

    www.yahoo.com/news



    Hope someone can offer a script for this or an alternative easy to use method.
  • xxxoutsourcing
    Confirmed User
    • Oct 2003
    • 3888

    #2
    PHP Code:
    <?php echo  $id[0]; echo $1d[1];?>
    you need something like this, the more ID's you add the more code you can carry on your ?id=123456
    the above code is good for only two

    xxxoutsourcing.com
    ICQ:119936 | Aim:xxxoutsourcing | MSN:msn@ xxxoutsourcing.com | Yahoo:xxxoutsourcing
    Submitters, Designers, Programmers, Cartoonist, Creative Writers, Video & Photo Editors
    Convert your Paysite into a cartoon site convert2toons.com

    Comment

    • mkx
      Confirmed User
      • Nov 2003
      • 4001

      #3
      Thanks, but I don't think this solves the problem on keeping the variable stored so I can use it on the next page. I am testing out some cookie functions now, I think that is what I needed.

      Comment

      • SilverTab
        Confirmed User
        • Nov 2001
        • 5060

        #4
        Originally posted by raulph
        Quick question, I am trying to make it so that a variable is kept even when the user clicks to another page. For example:

        They go to www.yahoo.com?ref=55

        and then from yahoo they click news. I want it to then go to:

        www.yahoo.com/news?ref55

        instead of just going to

        www.yahoo.com/news


        Hope someone can offer a script for this or an alternative easy to use method.
        well let's say you go to
        www.url.com/index.php?id=1234

        you can print the variable in your page by using <?=$id?>
        so just print it in your link...
        (let's say you want news.php to carry the variable you would use
        PHP Code:
        <a href="news.php?id=<?=id?>">
        or you can store it in a session variable if you want to carry it around on multiple pages etc etc.....lots of ways to do it..
        Last edited by SilverTab; 11-24-2004, 12:49 AM.
        mmm my sig was too big... no more cool animation
        but hey still! need php? ICQ: 94586959

        Comment

        • SilverTab
          Confirmed User
          • Nov 2001
          • 5060

          #5
          Originally posted by raulph
          Thanks, but I don't think this solves the problem on keeping the variable stored so I can use it on the next page. I am testing out some cookie functions now, I think that is what I needed.
          in this case, what you want is a session variable...
          mmm my sig was too big... no more cool animation
          but hey still! need php? ICQ: 94586959

          Comment

          • V_RocKs
            Damn Right I Kiss Ass!
            • Nov 2003
            • 32449

            #6
            PHP Code:
            <a href=http://www.nextlinkontthepage.com?ref=<? echo $ref; ?>>link</a>

            Comment

            • V_RocKs
              Damn Right I Kiss Ass!
              • Nov 2003
              • 32449

              #7
              after you drop the cookie,
              PHP Code:
              <?=$_REQUEST['ref']; ?>
              So php checks the cookie, post and get requests for the info.

              Comment

              • mkx
                Confirmed User
                • Nov 2003
                • 4001

                #8
                PHP Code:
                <a href="news.php?id=<?=id?>">
                This seems like the easiest method for what I am doing. Thank you guys so much, nice to get instant php support at 5am ;)

                Comment

                • mkx
                  Confirmed User
                  • Nov 2003
                  • 4001

                  #9
                  [QUOTE]Originally posted by raulph
                  [B]
                  PHP Code:
                  <a href="news.php?id=<?=id?>">
                  Got it working but you forgot the $ in <?$id?>">

                  Thanks again guys!

                  Comment

                  • BastarD
                    Confirmed User
                    • Apr 2004
                    • 6341

                    #10
                    Try using smarty (smarty.php.net), they have something like $smarty -> assign;

                    Comment

                    • StuartD
                      Sofa King Band
                      • Jul 2002
                      • 29903

                      #11
                      Originally posted by raulph
                      PHP Code:
                      <a href="news.php?id=<?=id?>">
                      This seems like the easiest method for what I am doing. Thank you guys so much, nice to get instant php support at 5am ;)
                      asking a php question... and only needing to know how to do that..

                      that's like stepping into a fomula 1 car and asking how to step on the gas.
                      This is me on facebook
                      This is me on twitter

                      Comment

                      Working...