Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

php passing and assigning variables

Posted by jon@joco.myrf.net (JoCo), 16 August 2007
Sorry i'm a noob when it comes to php. I am trying to pass a variable through a URL, and assign variables to images server side. The effect I am trying to achieve is a different image based on the variable I pass through the link. I am looking for some direction or resources to where I might start on this project. Thanx for any help or links to info.

Posted by jon@joco.myrf.net (JoCo), 16 August 2007
Here's what I have so far...

This is the html to display the image.
[table][tr][td]

<img src="<?php echo #_Request['VariableName']?>.gif">
[/td][/tr][/table]

I am pretty sure I can figure out the URL from the other "Passing Variables through URL forum topics"

However where I'm lost is assigning the images to the variables.

Posted by admin (Graham Ellis), 16 August 2007
Try replacing

<?php echo #_Request['VariableName']?>

with

<?php echo $_REQUEST['VariableName']?>

It's a $ not a # for a variable, and REQUEST is all in capital letters.   You should then be able to add ?variableName=willy after your URL and it wil bring in the image willy.gif.

If it doesn't work, have a look at what your browser has received via "view source"

Posted by jon@joco.myrf.net (JoCo), 16 August 2007
sweet! thank you...that works. Now another question. How would I accomplish this if the images aren't on the same server as the web page?

Posted by admin (Graham Ellis), 17 August 2007
<img src="http://www.whereitis.com/<?php echo $_REQUEST['VariableName']?>.gif">

Posted by jon@joco.myrf.net (JoCo), 24 August 2007
ok i was going about this completely wrong.
here is my page code.
<html>
 <head>
   <title>
   test
   </title>
 <body>

<?php
$pic = $_Request['variablename'];
?>

<center><img src="<?PHP echo $_Request['pic']?>.gif" /></center>
</body>
</html>


and this is how i'm linking to it : http://blank.com/test.php?pic=linux

file is saved as test.php and image is linux.gif

still not working. am i missing something?


Posted by jon@joco.myrf.net (JoCo), 24 August 2007
Sorry for being dense
.




<?php
$pic = $_REQUEST['VariableName'];
?>
<html>
 <head>
   <title>
   test
   </title>
 <body>
<img src="<?PHP echo $_REQUEST['pic']?>.gif" />
</body>
</html>

and then linking with

http://blank.com/test.php?pic=linux

works like a charm. forgot about he REQUEST having to be in caps. Thanks again Graham.

Posted by admin (Graham Ellis), 25 August 2007
on 08/24/07 at 20:19:10, JoCo wrote:
Thanks again Graham.


Glad it's working ... been a busy day - a i was a.f.k (away fro this keyboard) for 24 hours ...

-- Graham

Posted by jon@joco.myrf.net (JoCo), 6 September 2007
Sorry gotta rehash this issue as I'm playing with it more. Is there a way I can tell the browser to ignore the image tag if there is no variable present? so if you were to go directly to http://www.yoursite.php instead of http://www.yoursite.php?variablename=blank
that way there isn't a broken image tag.

Posted by admin (Graham Ellis), 6 September 2007
replace

<img src="<?PHP echo $_REQUEST['pic']?>.gif" />

with

<?php if ($_REQUEST[pic]) {
 ?><img src="<?PHP echo $_REQUEST['pic']?>.gif" /><?php } ?>

(it can be shorter, but I've gone for a clearer form!)

Posted by jon@joco.myrf.net (JoCo), 6 September 2007
Thank you tons! I'm on the road to getting this stuff down. Your help is appreciated.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho