faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

87 of 106 people (82%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

how can i pass 2 variables from php and include it in a hyperlink? eg: <a href=($variable1)>$variable2</a>

Nov 27th, 2008 02:55
healthy man, dman, PHP Man, Philip Olson, Henrik Hansen, Jon Doe,


Passing GET variables is very simple.  For example:
<?php
  $id    = 100;
  $hi    = 'foobar';
  $title = 'Visit this page';
  echo "<a href='http://example.com/a.php?id=$id&hi=$hi'>$title</a>";
?>
The gist of it is, somefile.php?a=b&c=d&e=f&g=h  Now you may want to
make sure your passed variables are encoded properly, consider 
urlencode() :
  http://www.php.net/urlencode
Basically:
  $var = 'I have spaces & stuff';
  $var = urlencode($var);
  print $var; // I+have+spaces+%26+stuff
Read that urlencode manual entry for more information.  Retrieving 
these
GET variables can be done through many different ways, many of which
depend on your particular PHP settings.  Here are some ways to access
the GET information in a.php
If the deprecated register_globals directive is on then then $id 
will   
be available.  This used to be the most common method but because 
of security reasons, it's frowned upon.  So as per the above link:
  print $id;
  print $hi;
Better yet, go through a predefined variable.  Such as:
  print $HTTP_GET_VARS['id']; // A very common method
  print $_GET['id'];          // $_GET became available in php 4.1.0
It may seem like a pain (extra typing) to go through a predefined
variable but at least you'll know exactly where your data is coming
from.  More information on this matter can be seen:
  Using register_globals:
    http://www.php.net/manual/en/security.registerglobals.php
  Variables from outside PHP:
    http://www.php.net/manual/en/language.variables.external.php
====
webmasterworld.com/forum88/1999.htm 
hope that helps.
http://www.healthbyhealth.com
http://www.healthment.com
http://www.mesotheliomadown.com
http://www.mesotheliomaout.com
http://www.pickarticle.com