| | |
php url code?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Solved Threads: 0
Trying to display images in html by calling a php script in the img tag. php script fetches the image binary from mysql. image is not displaying. here is img tag
my question is, it seems people are using the "...php?id=1" to pass an identifier 'id' to the script. I haven't been able to find anything about how these work, what the syntax is, and whether this automatically creates a variable '$id' in the script with a value of 1, which is implied, but since i can't get the script to work i cannot determine if accurate. Can anyone either explain or point to a resource that handles this?
thanks!
matt
html Syntax (Toggle Plain Text)
<img src="getdata.php?id=1" />
my question is, it seems people are using the "...php?id=1" to pass an identifier 'id' to the script. I haven't been able to find anything about how these work, what the syntax is, and whether this automatically creates a variable '$id' in the script with a value of 1, which is implied, but since i can't get the script to work i cannot determine if accurate. Can anyone either explain or point to a resource that handles this?
thanks!
matt
The url: getdata.php?id=1 works just like a regular url on any php page, only difference with images the content type returned to the client/browser.
What php does is parse the URL sent to it via HTTP, in this case getdata.php?id=1.
If the HTTP method is "GET" as is the case, it will create a global variable $_GET.
$_GET is an associative array, with each parameter in the url set as an index, and the associated value as the value.
for getdata.php?id=1
[PHP]$_GET = array('id'=>'1'); // this is what PHP does automatically[/PHP]
so you can get the value with:
[PHP]$id = $_GET['id']; // will be equal to '1'[/PHP]
Older versions of PHP had a feature called "register globals" (I think). It automatically made every parameter passed in the URL a global.
Eg: for getdata.php?id=1
[PHP]$id; // will be equal to '1' in older php version, or when register globals is on[/PHP]
This isn't considered safe practice however, so may servers will disable it.
Something to note with generating images with php is that any output other than the binary data for the image will cause the image not to show.
So if you have a single error, everything messes up..
If you want to debug, find where you have the line:
[PHP]header("Content-Type: [/php]
and add a return or die(); right before it so you can debug. Otherwise your debugging will be interpreted by teh browser as part of the image data...
What php does is parse the URL sent to it via HTTP, in this case getdata.php?id=1.
If the HTTP method is "GET" as is the case, it will create a global variable $_GET.
$_GET is an associative array, with each parameter in the url set as an index, and the associated value as the value.
for getdata.php?id=1
[PHP]$_GET = array('id'=>'1'); // this is what PHP does automatically[/PHP]
so you can get the value with:
[PHP]$id = $_GET['id']; // will be equal to '1'[/PHP]
Older versions of PHP had a feature called "register globals" (I think). It automatically made every parameter passed in the URL a global.
Eg: for getdata.php?id=1
[PHP]$id; // will be equal to '1' in older php version, or when register globals is on[/PHP]
This isn't considered safe practice however, so may servers will disable it.
Something to note with generating images with php is that any output other than the binary data for the image will cause the image not to show.
So if you have a single error, everything messes up..
If you want to debug, find where you have the line:
[PHP]header("Content-Type: [/php]
and add a return or die(); right before it so you can debug. Otherwise your debugging will be interpreted by teh browser as part of the image data...
Last edited by digital-ether; Nov 13th, 2006 at 11:24 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Err, isn't it $_REQUEST[]?
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
![]() |
Similar Threads
- PHP URL variables and if statement (PHP)
- php drop down menu to search multiple sql tables (PHP)
- Image Rollover code (JavaScript / DHTML / AJAX)
- php contact page (PHP)
- PHP errors on netscape enterprise server (PHP)
- Installation of PHP on Windows (PHP)
- Please review my site Fridgemags.com (Website Reviews)
Other Threads in the PHP Forum
- Previous Thread: i do NOT see what is wrong with my code
- Next Thread: Order by statement
| Thread Tools | Search this Thread |
action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display domain dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link load login loop mail malfunctioning masterthesis menu mlm multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube






