473,729 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling a php script using img src ="random.php "

Hey all,

I have a small php script that calls a random image at the following
page.
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random image
the page is http://2006ymcanationals.com/index.php using <img
src="random.php ">

It is not working. I have tried using the full path to the
"random.php ". I have also tried naming the main page index.html and
index.php. neither work.

what am i missing? Searching these groups it looks like this should
work.

Thanks in advance.

Brad

Jul 17 '05 #1
12 9705

<bh*****@gmail. com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
Hey all,

I have a small php script that calls a random image at the following
page.
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random image
the page is http://2006ymcanationals.com/index.php using <img
src="random.php ">

It is not working. I have tried using the full path to the
"random.php ". I have also tried naming the main page index.html and
index.php. neither work.

what am i missing? Searching these groups it looks like this should
work.

Thanks in advance.

Brad


It's hard without looking at the code.
The images seem to be different names on the page. Eg. rimage2.jpg,
rimage3.jpg, rimage4.jpg, rimage5.jpg

Brent Palmer.


Jul 17 '05 #2
NC
bh*****@gmail.c om wrote:

I have a small php script that calls a random image
at the following page.
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get
a random image the page is http://2006ymcanationals.com/index.php
using <img src="random.php ">


Actually, in your index.php page, it's not <img src="random.php ">,
it's <img href="random.ph p">. Correct it, and everything should
work...

Cheers,
NC

Jul 17 '05 #3
bh*****@gmail.c om wrote:
IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random
image

It is not working.

what am i missing? Searching these groups it looks like this should
work.


You're outputting HTML from your PHP-script, not the image itself.

It's the same as if you try to have <IMG SRC="whatever.h tml"> - I
don't think you suppose that to work (unless whatever.html actually is
a very strangely named image file, of course).

What you should be doing in your script is to output suitable headers
for the image, and pass the image through your script. Something like
this:

<?php
$img_filename = 'test.gif'; // On serverside
// The above is what you can take as random...
header('Content-type: image/gif');
// header('Content-type: '.mime_content_ type($img_filen ame));
// Use this if your server supports it!
header('Content-length: '.filesize($img _filename));
$file_pointer = fopen($img_file name, 'rb');
fpassthru($file _pointer);
fclose($file_po inter);
exit;
?>

--
Markku Uttula

Jul 17 '05 #4
*** bh*****@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random image
the page is http://2006ymcanationals.com/index.php using <img
src="random.php ">


Your script does not return an image. It returns an HTML page that links to
an image. You cannot link to an HTML page with the <img> tag. Maybe you're
thinking of <iframe>?

You could either choose a random filename:

<img src="<?=get_ran dom_img_name()? >">

Or make your script return an actual image:

<?
header('Content-Type: image/gif');
readfile('foo.g if');
?>

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Jul 17 '05 #5
Thanks for all your help.

I dont know php well enough to write this stuff. I am following
instructions found here:
http://www.gatequest.net/misc/php/random-image.php

will this work?
Alvaro G. Vicario wrote:
*** bh*****@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random image the page is http://2006ymcanationals.com/index.php using <img
src="random.php ">
Your script does not return an image. It returns an HTML page that

links to an image. You cannot link to an HTML page with the <img> tag. Maybe you're thinking of <iframe>?

You could either choose a random filename:

<img src="<?=get_ran dom_img_name()? >">

Or make your script return an actual image:

<?
header('Content-Type: image/gif');
readfile('foo.g if');
?>

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie) ++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--


Jul 17 '05 #6

<bh*****@gmail. com> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
Thanks for all your help.

I dont know php well enough to write this stuff. I am following
instructions found here:
http://www.gatequest.net/misc/php/random-image.php

will this work?


Yes this works fine for me. As I said the images seem to be displaying with
different names which indicate to me that all is working.
What images do you have in the folder? Do they look the same?

Brent Palmer.
Jul 17 '05 #7
*** bh*****@gmail.c om escribió/wrote (16 Mar 2005 17:16:58 -0800):
I dont know php well enough to write this stuff. I am following
instructions found here:
http://www.gatequest.net/misc/php/random-image.php

will this work?


It should, given that you link to that script from the <img> tag.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Jul 17 '05 #8
On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
made "Alvaro G. Vicario" <kA************ *****@terra.es> write:
*** bh*****@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random image
the page is http://2006ymcanationals.com/index.php using <img
src="random.php ">


Your script does not return an image. It returns an HTML page that links to
an image. You cannot link to an HTML page with the <img> tag. Maybe you're
thinking of <iframe>?

You could either choose a random filename:

<img src="<?=get_ran dom_img_name()? >">

Or make your script return an actual image:

<?
header('Conten t-Type: image/gif');
readfile('foo. gif');
?>


You know... I'm experiencing a very similar issue.

In my case, I am building a counter script (* non-relevant reasons
below) and I have similar behavior. I call the script directly in its
own directory and it outputs the composite image fine. Calling it
from one directory higher from within an HTML file gives a broken
image.

Originally, I copied from another script that output multiple
individual gifs when the script was called. I never understood how
that was supposed to work, other than as a stand-alone script, so I
redid the code to copy each image jpg into one image that I output
from the script.

Relevant code:
<<<
//determine size of images in directory by testing the zero image
$source = $style_folder . "0." . $ext;
$img_size = @getimagesize( $source );
// $width is string length in characters
$dst_img=ImageC reate( $width * $img_size[0], $img_size[1] );

for ($i=0;$i<strlen ($countstring); $i++) {
$digit=substr(" $countstring",$ i,1);
// Build the image URL ...
$source = $style_folder . $digit . "." . $ext;
$src_img = imagecreatefrom jpeg( $source );
// $source = $base_url . $style_folder . $digit . "." . $ext;
// echo "<img src=\"$source\" border=0>";
imagecopy( $dst_img, $src_img, $i * $img_size[0], 0, 0, 0,
$img_size[0], $img_size[1]);
}

header( "Content-type: image/jpeg" );
ImageJpeg($dst_ img);

exit();
<<<

And from the calling HTML:
<<<
<img src="_Counters/jpbcount.php?li nk=Tester&style =odometer"
height="20" align="ABSMIDDL E">
<<<

I've tried calling the script with both an <img src= and <img
href= to no avail.

Any pointers?

Thanks.

-JPB

*Non-relevant rationale
I may be migrating my server over to a Linux-based hosting service
from my own Windows 2000-based server. I liberally used a CGI program
on my site and now that I may be going to a Linux-based system, I
figured I'd mimic the functionality of it in a more portable PHP
script.
Jul 17 '05 #9

"Dahak" <Da******@thefi fthimperium.com > wrote in message
news:pf******** *************** *********@4ax.c om...
On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
made "Alvaro G. Vicario" <kA************ *****@terra.es> write:
*** bh*****@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):
http://www.2006ymcanationals.com/random.php

IT WORKS IF I go directly to the above link.

I am trying to call that in another page so that i get a random image
the page is http://2006ymcanationals.com/index.php using <img
src="random.php ">


Your script does not return an image. It returns an HTML page that links toan image. You cannot link to an HTML page with the <img> tag. Maybe you'rethinking of <iframe>?

You could either choose a random filename:

<img src="<?=get_ran dom_img_name()? >">

Or make your script return an actual image:

Here's a working example that might help. This checks to see if a website is
up and if it is, it displays a smiley gif and if not, a not so smiley gif in
a table of smileys. Now the page doesn't wait for ALL the smileys to not
time out before displaying; rather it displays the whole table immediately
and these pop up as they finish running. Now if it would only display a
"processing " gif while we waited :>)

==== An Actual Table Row ======

<tr>
<td>Logon.net </td>
<th><img src="/frag/status.php?addr =www.logon.net" width="37"
height="20"></th>
<th><img src="/frag/status.php?addr =mail.logon.net &port=25" width="37"
height="20"></th>
<th><img src="/frag/status.php?addr =mail.logon.net &port=110" width="37"
height="20"></th>
<th><img src="/frag/status.php?addr =mail.logon.net " width="37"
height="20"></th>
<th>&nbsp;</th>
</tr>

==== status.php has to be above Doc Root ===============

<?php
//Web Server Status v 1.2, Copyright 2002 By Ryan Schwiebert, visit
http://www.schwebdesigns.com/
//This script may be freely distributed providing all copyright headers are
kept intact.

//Concept from:
//Abax Server Status v1.04, Copyright 2002 By Nathan Dickman, visit
http://www.NathanDickman.com/
//Location of the live or dead server images

// Updated by John Jarrett 2003

//Please change to your server specifications
$live = "/frag/images/live2.gif";
$dead = "/frag/images/dead2.gif";

//The status checking script
//meddle at your own risk!
//check for port number, default is 80
#list($addr,$po rt)= explode (':',"$link");
if (empty($port)) {
$port = 80;
}

//Test the server connection

$churl = @fsockopen(serv er($addr), $port, $errno, $errstr, 20);
#$churl = @fsockopen($add r, $port, $errno, $errstr, 20);
if (!$churl){
header("Locatio n: $dead");
}
else {
header("Locatio n: $live");
}
function server($addr){
if(strstr($addr ,"/")){$addr = substr($addr, 0, strpos($addr,
"/"));}
return $addr;
}
?>

====== end of script =====

hth,
John
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2177
by: Mike Bobbitt | last post by:
I've recently decided to switch from compiled Apache/PHP to RPM's of both and I'm having a problem I can't seem to solve. I have a Perl script called php_include.cgi that parses a PHP file for inclusion. It does this by running "php -f " but unfortunately it no longer works with the RPM: ---------- Security Alert! The PHP CGI cannot be accessed directly. This PHP CGI binary was compiled with force-cgi-redirect enabled. This
5
2996
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure out how to do this in bash script as the requirement is necessary for a migration script to obtain the code from a .cfg file and then be able for the "parent" script to run the code it "imported" from the .cfg file, much like PHP's require() or...
0
1918
by: Matt Sale | last post by:
add this to your list of how NOT to configure apache 2.x for PHP. Never add this line to the httpd.conf: AddHandler cgi-script .php sign me: perpetual student at Hard Knocks U.
3
1499
by: David | last post by:
I found and interesting article, "Experiences of Using PHP in Large Websites" (http://www.ukuug.org/events/linux2002/papers/html/php/) , which lists some issues with scaling PHP for larger projects. Worth a read although it appears to be three years old. The major issue I have had with PHP is a conflict in class names for modules created by two project teams. We resolved this by prefixing all class names with a module ID, ex....
4
5102
by: Jesse Noller | last post by:
Hello - I'm probably missing something here, but I have a problem where I am populating a list of lists like this: list1 = list2 = list3 = main_list =
10
31703
by: FX | last post by:
I wanna publish a script on my site which allows me to hide image source. i have rough idea abt it. i`ll point src to some php page like: <img src="image.php"> & in tht php wat exactly shud be done so tht user doesnt come to know the real source location of image file upon clicking its properties. I've seen websites doing this. can somebody post the script for it? Thanx in advance
5
3209
by: Jim Carlock | last post by:
I've set up the following using an Alias in Apache... Alias /phpdocs/ "C:/Apache/htdocs/common/docs/php/" <Directory "C:/Apache/htdocs/common/docs/php"> Options Indexes FollowSymlinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
3
6016
by: Larry Leonard | last post by:
Running MSDE 2000 SP2 on Windows XP SP3. I have a T-SQL script that is relatively simple (adding constraints, inserting rows, etc.) and short (maybe 300 lines, heavily commented). It's an upgrade script I wrote weeks ago, and has worked fine everywhere. After the patch from last Wednesday. "Security Update for SQL Server 2000 Service Pack 4 (KB948110)", I have gotten the following error on two different machines, using a copy of the...
5
11801
bilibytes
by: bilibytes | last post by:
hi, i am making a website with php OOP. i have a class called session: it has the attribues -logged_in; -user_name; -user_ip; -user_level;
0
8760
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2673
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.