944,018 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 13707
  • PHP RSS
Nov 13th, 2006
0

php url code?

Expand Post »
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

html Syntax (Toggle Plain Text)
  1. <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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
went1180 is offline Offline
9 posts
since Sep 2006
Nov 13th, 2006
0

Re: php url code?

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...
Last edited by digital-ether; Nov 13th, 2006 at 11:24 pm.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Nov 15th, 2006
0

Re: php url code?

by god man that was a succinct, clear answer and i thank you for it. now if only my f***ing script was working...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
went1180 is offline Offline
9 posts
since Sep 2006
Nov 15th, 2006
0

Re: php url code?

Err, isn't it $_REQUEST[]?
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Nov 21st, 2006
0

Re: php url code?

er, madame, rather.....sry.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
went1180 is offline Offline
9 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: i do NOT see what is wrong with my code
Next Thread in PHP Forum Timeline: Order by statement





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC