What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP - Gestbook.... help

PHP - Gestbook.... help
Author: Message:
distorted
New Member
*


Posts: 4
37 / Male / –
Joined: Jun 2007
O.P. PHP - Gestbook.... help
Ok i'm trying to work on a script where my friends (who have photo's on there photobucket accounts etc....) can upload the img url to my form and it adds it to a flattext file, basicly its a modifyed guestbook, but i have little/no knowladge of PHP, i have got this to work in some shape or form, but whats making me struggle is i cant get the new entrys to go to the top of the page instead of being added to the bottom. i know its not possable to write to the top of a flat text, and the way to do this would be to get it to open the existing content from the file and then add that to the end of the new entry, and write it all in at once....? but i dont know how... any suggestions. heres my code:


<html>
<head>
<title>Upload</title>
</head>
<body>
<?php
include('config.php');
$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen("savedinfo.php", "a");
if (!$out) {
print("Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"<CENTER><font size='2' face='Verdana'><A href='$user' target='_blank'><img src='$user' width='300' height='200' style='border-color:#000000' border='1'></a><BR>$message<BR><BR></font></CENTER>");
fclose($out);
?>
</body>
</html>

user/name is the url of the image, message is simply a description. Thankyou in advance.

Kirk
06-19-2007 05:29 PM
Profile E-Mail PM Web Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
RE: PHP - Gestbook.... help
What's in config.php and where are your forms located :)?
06-19-2007 07:56 PM
Profile PM Find Quote Report
Baggins
Full Member
***

Avatar
B000ALFAZO

Posts: 387
Reputation: 13
29 / Male / Flag
Joined: Oct 2006
RE: PHP - Gestbook.... help
There is nothing in the script that is not defined there, I am guessing config.php is empty.

If you give me half an hour I will write a script for you, free of charge.
06-19-2007 08:22 PM
Profile E-Mail PM Web Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: PHP - Gestbook.... help
code:
<html>
<head>
<style type="text/css">
span.info{
text-align:center;
font-family:Verdana;
font-size:2;
}
</style>
<title>Upload</title>
</head>
<body>
<?php
include('config.php');
$user = $_GET["name"];
$message = $_GET["message"];
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
$out = fopen("savedinfo.php", "a");
if (!$out) {
print("Could not append to file");
exit;
}
fwrite($out,"<span class='info'><a href='".$user."' target='_blank'><img src='".$user."' width='300' height='200' style='border-color:#000000' border=1></a><BR>$message<BR><BR></span>".file_get_contents("savedinfo.php"));
fclose($out);
?>
</body>
</html>

will add the new entry on top of the new ones?

This post was edited on 06-19-2007 at 08:32 PM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
06-19-2007 08:23 PM
Profile PM Web Find Quote Report
Baggins
Full Member
***

Avatar
B000ALFAZO

Posts: 387
Reputation: 13
29 / Male / Flag
Joined: Oct 2006
RE: PHP - Gestbook.... help
code:
<html>
<head>
<title>Upload</title>
</head>
<body>
<?php
$user = strip_tags($_GET["name"]);
$message = strip_tags($_GET["message"], '<b><i><u><a>');
$handle = @fopen("./savedinfo.php", "r+");
if ($handle) {
    while (!feof($handle)) {
        $buffer .= fgets($handle, 4096);
    }
    fwrite($handle,"<CENTER><font size='2' face='Verdana'><A href='$user' target='_blank'><img src='$user' width='300' height='200' style='border-color:#000000' border='0'></a><BR>$message<BR><BR></font></CENTER>\n");
    fwrite($handle, $buffer);
    fclose($handle);
}
print("<b>Thank You!</b><br />Your information has been added! You can see it by <a href=savedinfo.php>Clicking Here</a>");
?>
</body>
</html>


This does exactly what roflmao's does, except it is safe from PHP and HTML injection, and allows for basic tags such as <b><i><u> and <a> in the message field.

I figure this method, opening the file for read/write, will be more efficent than filegetcontents() because you only need to open it once.

This post was edited on 06-19-2007 at 08:52 PM by Baggins.
06-19-2007 08:39 PM
Profile E-Mail PM Web Find Quote Report
distorted
New Member
*


Posts: 4
37 / Male / –
Joined: Jun 2007
O.P. RE: PHP - Gestbook.... help
Thankyou all for your prompt replys. i will try the suggested ways and see which works for me :D and yes config.php is empty, not to sure why its there either, was just in the tutorial i used to make it. thanks again x
06-20-2007 09:44 AM
Profile E-Mail PM Web Find Quote Report
distorted
New Member
*


Posts: 4
37 / Male / –
Joined: Jun 2007
O.P. RE: PHP - Gestbook.... help
For some reason Baggins when i use your script it sort of works (as in new entrys go to the top) but for some reason it dosent overwrite the existing entrys it just adds the new one with the old ones again, for exaple when i upload twice i have 3 images, as the second time it adds the new image to the old and then places the new and old image behind the old one alredy there. so it goes.

upload once:

Image 1        //new

Upload Twice:

Image 1       //existing entry
Image 2       //new
Image 1       //new

after 3 uploads i have 7 images. as it adds the new one to the top of the list then writes that below the existing 3.

understand what i mean?

and when i use your's roflmao's i get this error message.

Fatal error: Call to undefined function: file_get_contents() in c:\apache\htdocs\sendinfo.php on line 23

help??
06-20-2007 10:06 AM
Profile E-Mail PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP - Gestbook.... help
quote:
Originally posted by distorted
Fatal error: Call to undefined function: file_get_contents() in c:\apache\htdocs\sendinfo.php on line 23
What PHP version are you running? It must be ancient (2002 or earlier) if it doesn't have file_get_contents()... :-/

To check the version, you can use phpinfo().

If you want to fix the code Baggins posted, adding this line right before the first "fwrite" line should do the trick...

code:
rewind($handle);
06-21-2007 02:10 AM
Profile PM Web Find Quote Report
distorted
New Member
*


Posts: 4
37 / Male / –
Joined: Jun 2007
O.P. RE: PHP - Gestbook.... help
Thankyou so much WDZ your a life saver it now works perfectly. i'm running PHPTRIAD to test scripts so i presume it is rather acccent. thanks again. x
06-21-2007 07:00 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On