PDA

View Full Version : My PHP shtuff


Phait
02-03-2005, 12:55 AM
8-Ball w/ Images:
http://www.phait-accompli.com/crap/php/misc/8ball/8ball_img.php

Wo0t!

Text 8-Ball:
http://www.phait-accompli.com/crap/php/misc/8ball.php

Quake Map Name Generator:
http://www.phait-accompli.com/crap/php/misc/quake_map.php

Madlibs type stuff:
http://www.phait-accompli.com/crap/php/misc/ph8libs.php

I'm also working on 2 in-progress things: a text file news update system (nearly done, just need to fix a little / problem) and a checklisting system that is a bit challenging right now, but I've learned arrays and file input/output in the process!

This shites fun, I tried learning PHP a couple years ago and just could'nt do it. Suddenly when I actually need something useful I'm learning.

ADM
02-03-2005, 05:07 AM
Nice work! PHP is fun and I've been doing it for along time now as well.

The best work I've done is a shoutbox, which I've taken down now since I'm currently attempting a forum.. with not much luck at the moment, mainly because I'm lazy http://forums.3drealms.com/ubbthreads/images/graemlins/wink.gif

Keep it up! The best way to learn is by doing little projects and working your way bigger and bigger!

Phait
02-03-2005, 01:01 PM
Right now I'm trying to write a checklist script that stores the checks in a file, so when the person goes back to the page, their checks are still there. Also, depending on what is checked, each task variable says YES or NO. I have all thsi working except no way to remember the checks if you were to refresh or exit.

I might have to look into cookies, but I'd like to keep it simpler. But at this point, it's pretty hard trying to get this working in a file.

ADM
02-04-2005, 12:39 AM
Cookies are probably the ideal way to do that.. I don't know I just don't like using text files myself.

I'm a database and cookie type of guy http://forums.3drealms.com/ubbthreads/images/graemlins/wink.gif

KillerByte
02-04-2005, 04:54 AM
ADM said:
I'm a database and cookie type of guy http://forums.3drealms.com/ubbthreads/images/graemlins/wink.gif



http://forums.3drealms.com/ubbthreads/images/graemlins/love.gif

I have to agree with ADM. PHP coupled with MySQL is one of the best combinations you will come across for web development. It really opens up a whole new load of possibilities.

Phait
02-04-2005, 12:15 PM
I will probably get into MySQL later down the road, but it seems so much easier to give someone a script and a text file.

ADM
02-04-2005, 12:21 PM
It is.. but well you have alot more opportunites when you add SQL into the mix. Amazing stuff can be done that is either very limited or too slow to do with text files.

MentalSentinel
02-04-2005, 12:40 PM
I find MySQL a lot easier than txt files actually.
There's no minus about it when compared to txt files.
Well, maybe just the lack of free hosts that support it.

Destroyer
02-05-2005, 12:11 AM
cool. but it seems to be broken. its giving me 2 different answers for the same question. http://forums.3drealms.com/ubbthreads/images/graemlins/wink.gif

ADM
02-05-2005, 05:49 AM
Destroyer said:
cool. but it seems to be broken. its giving me 2 different answers for the same question. http://forums.3drealms.com/ubbthreads/images/graemlins/wink.gif



I don't know if you're being sarcastic or not.. but .. umm.. yeah.

Phait
02-06-2005, 03:25 PM
Basic skin
http://www.phait-accompli.com/crap/php/skin/skin.php

Been wanting to learn that for quite awhile... next I need to learn sessions so the user can keep viewing the skin they prefer.

Phait
02-16-2005, 11:40 PM
Here's a question:

Basically I have a couple files:

index.php (root)
nav.txt [has image tags to display images] (root)

if I include() nav.txt in any root .php doc, it works fine and the images show. If I include() nav.txt from say, article/blah.php then obviously the images won't show, it expects them in the directory /article/

Is there any way for it to properly display the images in root, via the include, without having to use a huge chunk of coding, and without having to copy nav.txt to the /article/ directory? I'm trying to do this a bit more efficiently, and currently I have to pretty much copy each particular .TXT file to the dir. While it's not a huge deal, I wish I wouldn't have to do it.

Also, no database suggestions, not ready for that yet. Thanks.

ADM
02-17-2005, 02:31 AM
Use the variable $_SERVER['DOCUMENT_ROOT'] to define the root and then just have the file.. so even if you are in the article directory it'll look at your root directory first.

<?php include $_SERVER['DOCUMENT_ROOT']."/nav.txt"; ?>

Though it's probably ideal adding the variable to the image url's as well so the site knows that the images are there.

Phait
02-17-2005, 08:48 AM
Doesn't work, images still don't show up. If you meant to use it in the images like this:

<img src=SERVER['DOCUMENT_ROOT']."/img.gif"> that doesn't help either...

ADM
02-17-2005, 01:27 PM
Yeah the images won't show up like that..

it'd have to be something like:

<?php echo "<img src=\"".$_SERVER['DOCUMENT_ROOT']."/img.gif\"/>"; ?>

or something like that.. forgive me.. it's 3:30am and I know I probably missed out some slash or something out of the above.

Phait
02-17-2005, 06:51 PM
Yeah, that doesn't work either :P

I actually have something working now...

by splitting the page into:

header.php
content.php
footer.php

I can retain all my navigation and main body code/images in header/footer, while the main content is in content.php (or whatever the page is). Then, I have no problems except that:

I have to put in all my images <img src="/written/image.gif"> when, 'written' is the directory on my LOCAL server, i'd have to change it for the actual server, unless I provide a variable that can looook into the SERVER ROOT, and go UP ONE folder (since it'll be in www.phait-accompli.com/personal/ (http://www.phait-accompli.com/personal/) most likely).. sure I could just replace 'written' with 'personal', but it'd be neat to keep ths more portable so the next time, if I do any redesign/redev I don't have to worry much about directory structures.

Another thing I was thinking of doing is something like this.. well I'm partially doing it, except for the link variables:

http://www.gurusnetwork.com/tutorial/php_templates/

I read the problem with URL's like http://www.site.com/page.php?module=this

is that search engines do'nt index it, it'd have to be http://www.site.com/module/this.php or somesuch. I did read a way to kind of spoof the URL from the first example into the second example, while retaining the dynamic URLs, but a bit much, and I'm not trying to use someone else's code bit for bit, even if it is a tutorial (I'm trying to learn on my own, with hinting along the way).

Thanks for your help.

ADM
02-18-2005, 12:00 AM
You could just link the image to the actual full url.

<img src="http://www.phait-accompli.com/personal/written/image.gif">

But glad you got around it anyway.. don't know why my code didn't work but nevermind now I guess http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif

As for url's like this:
http://www.site.com/page.php?module=this

not getting picked up by search engines. That was true about a couple of years ago, they are smarter now and can pick them up.

Also yeah modrewrites can make it so the above url would be http://www.site.com/page/module/this.php

I had the above working on the old Max Payne Dev site, works nicely http://forums.3drealms.com/ubbthreads/images/graemlins/smile.gif

Phait
02-18-2005, 07:55 AM
Cool, I got dynamic urls working with a couple lists.

I am near done with a comments script but I've been searching around for a way to prevent the user from submitting more than once. After submit, the user is redirected to another page, but you're still able to submit multiple times. Any suggestions?

ADM
02-18-2005, 11:23 AM
So you only want them to post once and then that's it.. they can't post again?

If so the best way would be to grab their IP and log it into a text file. Then get the script to search through that text file and if it finds a match then don't let them post.

The bad thing with text file databases is that the bigger the text file itself the longer it takes to search through it and the more resources it uses.

So the best thing to do would be to create a directory called ipcheck or something and then get the script to write a seperate text file for every IP.

So for example in that ipcheck directory there would be files called:

205.115.172.7.txt
217.135.231.18.txt

and so on... then get the script to search the directory for their IP (get it to ignore the .txt extension.. or if you really want you can get the script to not write an extension for the file in the first place) and then if it makes a match echo an error message out and then die.

I'm not too good at storing with text files (as I just jumped straight into DB's) so I'm not too sure how to go about this but it's easy to figure out someones IP. PHP has a predefined variable for it: $_SERVER['REMOTE_ADDR']

Good luck http://forums.3drealms.com/ubbthreads/images/graemlins/smile.gif

Phait
02-18-2005, 06:25 PM
They can post again, just not accidentally or purposely click the submit button more than once, for instance if they put in a URL or just some random BS to ****up the page w/ useless 'comments'. A timer would work, but that'd require sessions or cookies, which I haven't gotten into yet.

ADM
02-18-2005, 06:33 PM
Yeah cookies is the best idea.. just set a time and don't let them post between a certain amount.. and then if it exceeds another amount then let them post.

Phait
02-26-2005, 11:34 PM
Well, here's a new problem. I would post the page to show you but it's under construction for a client.

I have made a simple URL variable script so you can work with stuff like http://www.site.com/index.php?page=thatpage

Well, depending on the page they choose, it'll include a .TXT file relevant to that page (like if the URL is page=thatpage, then thatpage.txt will show, etc etc.). This works great, no problems. Well, below the line where I define that, I put in another variable so that it'll echo an image tag, and there is a variable in the image tag to display that section's particular image header.

The way everything is setup, the image header should display above the content .TXT - but it doesn't! All of it displays fine, it's just the image displays BELOW the content text - and it's so weird.. I've run this by another PHP guy and he suggested switching the order of a block of statements, which didn't work and threw 2 errors. Then we tried another switch which produced no errors, but the problem still existed. Here is the variable link code:

VARS.TXT

<?
if($info == news){
$item="news.txt";
$h="h_news.gif";
}
elseif($info == aboutus){
$item="aboutus.txt";
$h="h_about.gif";
}
elseif($info == contact){
$item="contact.txt";
$h="h_contact.gif";
}
else {
echo("Nothin' to see here boy.");
}
if($info) {
$head = "<img src='img/$h'>";
$showpage = $data = file($item); foreach($data as $line) print(nl2br($line));
}
else { $head = NULL; $showpage = NULL; }
?>


And in the index2.php page, I have this to display the TXT and image depending on the link chosen:

INDEX2.PHP CODE BIT

<? include("vars.txt"); ?><?=$head; ?><br><? $showpage ?>

Any idea? I might just have to stick with normal links to seperate pages, and just use the variable stuff for 1 of the sections (that has other pages beneath it, where I won't have to worry about changing that section's relevant header image).

Phait
02-27-2005, 01:53 PM
NEVERMIND -- a friend fixed it, but I decided not to use it right now.

Currently I am half done with a member creation/editing system - you put in a first, last and nickname along with some other details, and it creates a .txt file for each member. This is useful for a Doom 3 mod site I'm working on, so they won't have to go through one text file full of all the member's info http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif

I'm so proud, I never thought I'd get this far. http://forums.3drealms.com/ubbthreads/images/graemlins/cool.gif http://forums.3drealms.com/ubbthreads/images/graemlins/love.gifPHP http://forums.3drealms.com/ubbthreads/images/graemlins/love.gif

MentalSentinel
03-02-2005, 03:44 AM
You should use MySQL for something like that. That's a lot safer.

Phait
03-02-2005, 10:03 AM
Everyone tells me to, but I won't.

TXT is more portable, don't have to add-in/config a DB. Besides that, I'm too mired learning PHP now to stop and learn MySQL especially when I'm working on someone else's site(s).

I am interested in it though, just not at this point.

Phait
03-04-2005, 03:10 AM
File Uploading

I've scoured the web on this problem, but I've found out the cause of my my upload script won't work - you need to be able to set the temp dir in PHP.INI on the server - problem is, who ever has access to that file on a server? Certainly not me! I read you could set the dir via .htaccess, but it wasn't explained how - and then I read you couldn't do that.

I checked my host with phpinfo() and:

upload_tmp_dir = NO VALUE
file_uploads = ON

So I'm confused, how am I to get file uploads working?

ADM
03-04-2005, 03:31 AM
You could always contact your host and get them to set a temporary directory for you. I have seen ways to go around this, but can't remember off the top of my head.

Phait
03-04-2005, 12:25 PM
I've read about an ini setting function and I'm getting 2 different stories and I'm just confused.

The thing is, the file upload isn't for me. What if I need to configure the client's server somehow... blah. Should I just take out the temporary directory bit of code, or is that there for a particular security reason?

ADM
03-04-2005, 06:15 PM
I think that's needed by the server, since all uploads will go there and then moved to whichever directory you specified in your script.

Not too sure about that though, haven't really looking into uploading that much since it's heavily restricted (most hosts only allow up to something like 10mb for files to be upload via HTTP).

Phait
03-04-2005, 08:57 PM
I'm gonna look into I believe ini_set or some such. The uploads aren't big, just member profile pictures, GIF, with a size cap. I'm also doing a check for mimetype and file extension to be safe.

Phait
07-06-2005, 01:48 AM
Hey again. THis time I'm attempting a real simple e-mail newsletter thing.

Problem is, after it checks for absence of @ in the address (works) or existence of that address (works) - it won't write to the file - it used to, before I put this stuff in and mangled the if/else stuff, and I can't figure out what I'm doing wrong. It has to be with my usage of the exit; command I think... but I've taken them out and it still doesn't work:

http://www.phait-accompli.com/crap/sub.phps

Phait
07-08-2005, 10:37 AM
I fixed it with a bit of help and some searching. I'm working on the rest of it.

SippyCup
07-19-2005, 01:31 PM
Hey, just posting a link for a good SQL tutorial.

http://www.w3schools.com/sql

If you take the time (maybe 20-30 minutes) to read through all of that, you'll understand SQL. After that it's just a matter of getting a webhost that has MySQL and phpMyAdmin (or downloading phpMyAdmin and installing it) and going from there.

You are right about text files being portable, 'cause it is kind of a pain to rewrite files for different databases. I wouldn't say one way is better than the other 100%. Using MySQL is very useful, though. I do a lot of that. It's really handy for News pages, pic galleries, usernames and passwords, and forums.

Looks like you won't have a shortage of people who know what they're doing, though, when you're interested in learning it. http://forums.3drealms.com/ubbthreads/images/graemlins/hhg.gif