Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
Ok all I want to do is do something simple like put one php code in my page to make my pictures rotate. Well, I don't know what im not doing but when I went to the dreamhost control panel and searched on how to do it all I got was some cgi-bin to php stuff. What in the world does all this mean? Do I need to download or switch to something before I can use php on my sites? I thought it worked seemlessly with html and you just put it in as you wish. Please help! I need to get this site up and running.

Thanks!
 

dornoforpyros

macrumors 68040
Oct 19, 2004
3,070
4
Calgary, AB
jayeskreezy said:
Ok all I want to do is do something simple like put one php code in my page to make my pictures rotate. Well, I don't know what im not doing but when I went to the dreamhost control panel and searched on how to do it all I got was some cgi-bin to php stuff. What in the world does all this mean? Do I need to download or switch to something before I can use php on my sites? I thought it worked seemlessly with html and you just put it in as you wish. Please help! I need to get this site up and running.

Thanks!

my experience was I uploaded PHP and it worked, horray!

ok in all seriosness try putting this in a PHP file:
<?php echo "Hello World"; ?>

and seeing if it works. Make sure your saving your files as .php extentions as well.
yes php & html play very nicely together but you still must used the .php extention
 

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
Ok I dont understand any of what you wrote me unfortunately. I have dreamhost, but I don't know how to use php with it or even what php really is for that matter. I tried to go to the php site to learn about it, but it just made no sense to me. Now, I want to install a php forum but i cant. I want to use a php script on an html page. Is that possible?

How do I name something a php file and how does it work? For example: If I have a page called shoes.htm how do I make that a php page? Would it be shoes.php ?????

When I put a php script into my html page and try to test it I get this message:

No input file specified.


I know that might seem like something simple but what in the world does that really mean? I'm so lost. I had no idea this was going to be this difficult.

HELP!
 

theappleguy

macrumors 6502
Apr 19, 2005
321
0
Below is a basic script I put together for a site of mine a while back:

PHP:
<?php

srand((float) microtime() * 10000000);

$image[1]['pic']='http://www.yoursite.com/1.jpg'; 
$image[1]['link']='http://www.yoursite.com/1/';

$image[2]['pic']='http://www.yoursite.com/2.jpg'; 
$image[2]['link']='http://www.yoursite.com/2/';

$image[3]['pic']='http://www.yoursite.com/3.jpg'; 
$image[3]['link']='http://www.yoursite.com/3/';

$rn = array_rand($image);

echo '<a href="'.$image[$rn]['link'].'">'; 
echo '<img src="'.$image[$rn]['pic'].'">';

?>

Remember to make sure you change your page extension to .php. :)
 

ChrisWB

macrumors 6502
Dec 28, 2004
254
1,358
Chicago
Jay, php is a programming language like HTML. Certain programs, such as forums, blog-software and photo-gallery software are written in php. I also have Dreamhost. If you'd like help finding or installing anything feel free to send me a private message and I will walk you through the steps. :)
 

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
where do I put the php code? do I put that in the head? or body section of the webpage?

in a php page do I still put
<html>
<head>
</head>
<body>
</body>
</html>

like a regular html document and simply save it as whatever.htm or do I need some completely different code in the document?
 

theappleguy

macrumors 6502
Apr 19, 2005
321
0
First you need to place the PHP code whereever you want the image to appear on your page. Second, you need to change the page extension to .php. This tells the web server to process the code rather than display it as text. You must always enclose PHP code in <?php....?> tags.
 

dornoforpyros

macrumors 68040
Oct 19, 2004
3,070
4
Calgary, AB
jayeskreezy said:
How do I name something a php file and how does it work? For example: If I have a page called shoes.htm how do I make that a php page? Would it be shoes.php ?????

Yes, you must use .php to use php.
jayeskreezy said:
<html>
<head>
</head>
<body>
</body>
</html>

Yes all your basic HTML stuff must still be present.


Basically a PHP file (.php) is an HTML file with PHP code in it saved as a .PHP file.

so shoes.html + php code = shoes.php
 

notjustjay

macrumors 603
Sep 19, 2003
6,056
167
Canada, eh?
Does Dreamhost offer the Fantastico control-panel-installation interface? It might help you a lot for installing things like forums, especially if you don't know much about PHP.

I use VizaWeb for my hosting services (excellent value) and I've installed all kinds of PHP stuff on my website (http://www.kevlam.net) using almost no PHP coding of my own doing (and that includes following the installation instructions of prepackaged PHP tools).

Fantastico is a web-based interface where you point and click and tell it which script you wish to install (your host company pre-installs a selection) and after choosing a few options, you click "Go" and the next thing you know you have a working forum or blogging site or gallery. It's very handy. If your host provides it, use it. If they don't, maybe you can ask for it :)

That said, you sound like you know what you're doing in terms of HTML, so you're on your way. If you want to learn more about PHP I recommend the book I bought, "Programming PHP", by Lerdorf and Tatroe, published by O'Reilly books (generally, anything by O'Reilly books is excellent).

Good luck. I knew nothing about PHP when I started a year or two ago, and while I'm still no expert by any means, I'm finding lots and lots of cool stuff to do with it.
 

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
theappleguy said:
Below is a basic script I put together for a site of mine a while back:

PHP:
<?php

srand((float) microtime() * 10000000);

$image[1]['pic']='http://www.yoursite.com/1.jpg'; 
$image[1]['link']='http://www.yoursite.com/1/';

$image[2]['pic']='http://www.yoursite.com/2.jpg'; 
$image[2]['link']='http://www.yoursite.com/2/';

$image[3]['pic']='http://www.yoursite.com/3.jpg'; 
$image[3]['link']='http://www.yoursite.com/3/';

$rn = array_rand($image);

echo '<a href="'.$image[$rn]['link'].'">'; 
echo '<img src="'.$image[$rn]['pic'].'">';

?>

Remember to make sure you change your page extension to .php. :)


I like your code much better, but where do I place it in my document? Do I place it where i'd be placing the picture? I have it in a table cell so would I put the code in there? Or does it like go in the head or something?
 

theappleguy

macrumors 6502
Apr 19, 2005
321
0
Here is a quick explanation:

1) The $image parts are creating an array.
2) A random number is then selected, and thus and image is choosen
3) The echo statements basically write the HTML and add in the respective variables.

Just place it where you want the image to appear. :)
 

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
theappleguy said:
Below is a basic script I put together for a site of mine a while back:

PHP:
<?php

srand((float) microtime() * 10000000);

$image[1]['pic']='http://www.yoursite.com/1.jpg'; 
$image[1]['link']='http://www.yoursite.com/1/';

$image[2]['pic']='http://www.yoursite.com/2.jpg'; 
$image[2]['link']='http://www.yoursite.com/2/';

$image[3]['pic']='http://www.yoursite.com/3.jpg'; 
$image[3]['link']='http://www.yoursite.com/3/';

$rn = array_rand($image);

echo '<a href="'.$image[$rn]['link'].'">'; 
echo '<img src="'.$image[$rn]['pic'].'">';

?>

Remember to make sure you change your page extension to .php. :)


do I leave the 'http://www.yoursite.com/3/' part with the number as it is? I know I would change it to my site i.e. http://www.mysite.com but do I leave the "/3/'" part as it is?
 

SummerBreeze

macrumors 6502a
Sep 11, 2005
593
0
Chicago, IL
Why not check out Codegrrl, a tutorial website that will tell you some things you need to know to begin scripting in PHP. As a fellow dreamhost user, welcome to the world of <'s, ?'s, a few headaches and a dynamic site. You're gonna love it.

A bit of info that you might want to know is that installing scripts on dreamhost is a bit different from your average not-as-awesome host. Instead of using localhost for mysql databases, you have to use the hostname you create (typically something like wordpressdb.yoursite.com). This confused me for hours the first time I installed a few simple database scripts on dreamhost, so I figured I'd pass the information along.
 

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
SummerBreeze said:
Why not check out Codegrrl, a tutorial website that will tell you some things you need to know to begin scripting in PHP. As a fellow dreamhost user, welcome to the world of <'s, ?'s, a few headaches and a dynamic site. You're gonna love it.

A bit of info that you might want to know is that installing scripts on dreamhost is a bit different from your average not-as-awesome host. Instead of using localhost for mysql databases, you have to use the hostname you create (typically something like wordpressdb.yoursite.com). This confused me for hours the first time I installed a few simple database scripts on dreamhost, so I figured I'd pass the information along.

thanks...yeah I understood the database and message board and wordpress stuf...I mean it does it for you...what I want to know is exactly how to put the code in my document for the pictures to rotate every time the page is refreshed...thanks though
 

jayeskreezy

macrumors 65816
Original poster
Mar 3, 2005
1,137
0
MontyZ said:
In the script that theappleguy posted for you, this line is for your image:

$image[1]['pic']='http://www.yoursite.com/1.jpg'

So, if your image is called "mypic.jpg," then replace "http://www.yoursite.com/1.jpg" with "mypic.jpg." Same with the ['link'] line in the code, which is for the hotlink associated with the graphic.

If you know HTML, then this should make sense.

You can put PHP code anywhere in the file, but, in this case, just put the entire block of code (starting with <?php and ending with ?>) where you want the image to appear on your page. Simple.

And as has already been pointed out, the page MUST have a .php extension for the PHP code to be parsed by the PHP engine.


thanks monty...I did all that already though...I think im going to send theappleguy a copy of my code to see if he can tell whats wrong with it?
 

theappleguy

macrumors 6502
Apr 19, 2005
321
0
do I leave the 'http://www.yoursite.com/3/' part with the number as it is? I know I would change it to my site i.e. http://www.mysite.com but do I leave the "/3/'" part as it is?

All that the /3/ represents is a the directory that you are sent to when you click on a link. You can change it to whatever you want. If you post the adaption of my code you have used I will take a look and see what is going wrong with it. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.