What Did I Do Wrong (about random avatars)?

cgannon64

BOB DYLAN'S ROCKIN OUT!
Joined
Jun 19, 2002
Messages
19,213
Location
Hipster-Authorland, Brooklyn (Hell)
After checking out a thread about random avatars over at GC, and when I found out they worked here, I decided to try one. Here is my meager attempt at coding (based on what I read at GC). I need to know what I did wrong. I am not sure which site to include in the site, I just included the one I got the pics from. I'm not sure how to upload it (what site to put in in the URL). Here is the code:

randimg.php.txt

Thanks in advance. :)

CG
 
A few mistakes:

<?php

$img_array [0] = 'SpikeTwo.gif';
$img_array [1] = 'SpikeThree.jpg';
$img_array [2] = 'SpikeFour.jpg';

$img_root = "http://bebop268170.com/home.htm/"; ????
If the randimg.php is located at say http://www.site.com/path/randimg.php, you need to put http://www.site.com/path/ in this field.

Your random number generator initialization is missing:
srand(time());


$rand_int = rand(0, 2);

$chosen_img = $img_array[$rand_int];

header('http://bebop268170.com/home.htm/' . $img_root . $chosen_img);
Location: is not to be changed, the correct version would be:
header('Location: ' . $img_root . $chosen_img);

?>

And a few more things:
1. You file has to have a PHP extension, not a txt.
2. Your server has to support PHP scripting, e.g. Lycos does that.
:D
 
Thanks for the help, but this makes me think I can't do it. I don't have a site (I just used one arbirtrarily :D). I also don't have anything that saves in .php, so I guess I can't do it. :( Oh well, and thanks for the help, Lucky. I guess me and PHP don't mix...;)

CG

(Look at all those mistakes! :eek: ;))
 
Oh, and Lucky: do you know where I can find some intro into PHP? I'm interested in learning how to do it, and I think I should start with intro, not with...well...;) :lol:

CG
 
CG -

I can't program in php, so can't comment too much. However, re the .php extension - its just that - an extension.

All you need to do is rename you file to randimg.php, which you can do in explorer by right-clicking and choosing rename.

You don't have to actually have a special program to "save" it as a php file. :)
 
I write my PHP programs in a simple text editor, even notepad is good enough. ;)

As for the php-able server, a Lycos account is free and supports PHP. Not that I would recommend using it, but it is a possibility. :mischief:

As an intro to PHP and much more I can recommend www.php.net .
This should be your number 1 source for everything related to PHP programming. The feature an introductory tutorial as well as an online manual and an easy to browse function list. As well as many links to additional resources. :yeah:

My suggestion would be to combine learning PHP with learning C or Java, as those languages are very similar. PHP is more directed at webscripting applications, whereas C and Java can be used for "real" programs.
If you know C/C++ or Java, or at least a little Pascal or Delphi, then you shouldn´t have too many problems getting into PHP.
:D
 
Originally posted by ainwood
CG -

I can't program in php, so can't comment too much. However, re the .php extension - its just that - an extension.

All you need to do is rename you file to randimg.php, which you can do in explorer by right-clicking and choosing rename.

You don't have to actually have a special program to "save" it as a php file. :)

not quite, since the server has to parse the file. The server must be set up to parse all files with .php extensions as PHP. if you called the file randimg.bob, then it wouldn't be parsed as PHP unless the server was setup to do so.
 
Originally posted by Black Fluffy Lion


not quite, since the server has to parse the file. The server must be set up to parse all files with .php extensions as PHP. if you called the file randimg.bob, then it wouldn't be parsed as PHP unless the server was setup to do so.
:confused: OK - but it still means that you should be able to rename a file to have a .PHP extension, and it will then be recognised by a suitably-enabled server?
 
If the server is set up properly it should try to parse every *.php file. Sometimes php files are also names *.php4 or the like, corresponding to their version and most servers accept that automatically, too. :yeah:

But then, the file has to contain actual php code to work at all, of course. ;)
:D
 
Back
Top Bottom