Jump to content

Php Script Manipulation


roadmap

Recommended Posts

Hello, I have this webring script I need some help in changing. I'm trying to get it to ask people who sign-up for it to ask for 468x60 banners and have the script display it. Can anyone figure this out for me? I don't know what to do. Here are the codes:

 

config.php

<?

// The Name of your Web Ring.

$ring_name = "T-Shirt Ring";

 

// The URL to the webring home.

$url = "http://www.mysite.com/webring";

 

// The admin email address.

$adminmail = "webring@mysite..com";

 

// The directory where new submissions are stored.

$submitdir = $DOCUMENT_ROOT . '/webring/incoming';

 

// The directory where member sites info is stored.

$memdir = $DOCUMENT_ROOT . '/webring/members';

?>

functions.php
<?

 

// Parses data from form and stores it in a file in the $submitdir.

function submit_site($name, $email, $site_name, $site_url, $description)

{

global $submitdir, $memdir;

 

if ($name && $email && $site_name && $site_url && $description)

{

$name = stripslashes($name);

$email = stripslashes($email);

$site_name = stripslashes($site_name);

$site_url = stripslashes($site_url);

$description = stripslashes($description);

 

$data = "$name\n$email\n$site_name\n$site_url\n$description";

 

$fname = date("YmdHis");

 

if ( $fp = fopen($submitdir.'/'.$fname, 'w'))

{

fwrite($fp, $data);

}

return true;

}

}

 

// Views all entries in $submitdir awaiting action

function view_submissions()

{

global $submitdir, $memdir;

$submissions=opendir("$submitdir");

 

$files = array();

while ($file = readdir($submissions))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

for (reset ($files); list ($key, $value) = each ($files); )

{

$name = $value;

$this = file("$submitdir/$value");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "0")

{

echo "[<A HREF=$PHP_SELF?mode=approve&site=$name>Approve Site</a>] ";

echo "[<A HREF=$PHP_SELF?mode=reject&site=$name>Reject Site</a>]<BR>";

echo "<B>Name:</B> $value<BR>";

}

if ($key == "1")

{

echo "<B>E-Mail:</B> <A HREF=mailto:$value>$value</A><BR>";

}

if ($key == "2")

{

echo "<B>Site Title:</B> $value<BR>";

}

if ($key == "3")

{

echo "<B>Site URL:</B> <A HREF=$value TARGET=_New>$value</A><BR>";

}

if ($key == "4")

{

echo "<B>Description:</B><BR>$value<BR>";

}

if ($key > "4")

{

echo "$value<BR>";

}

}

echo "<HR>";

}

}

 

// Virtualy identical to view_submissions, but uses $memdir and has different options.

function view_members()

{

global $submitdir, $memdir;

$members=opendir("$memdir");

 

$files = array();

while ($file = readdir($members))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

for (reset ($files); list ($key, $value) = each ($files); )

{

$name = $value;

$this = file("$memdir/$value");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "0")

{

echo "[<A HREF=$PHP_SELF?mode=edit&site=$name>Edit Site</a>] ";

echo "[<A HREF=$PHP_SELF?mode=delete&site=$name>Delete Site</a>]<BR>";

echo "<B>Name:</B> $value<BR>";

}

if ($key == "1")

{

echo "<B>E-Mail:</B> <A HREF=mailto:$value>$value</A><BR>";

}

if ($key == "2")

{

echo "<B>Site Title:</B> $value<BR>";

}

if ($key == "3")

{

echo "<B>Site URL:</B> <A HREF=$value TARGET=_New>$value</A><BR>";

}

if ($key == "4")

{

echo "<B>Description:</B><BR>$value<BR>";

}

if ($key > "4")

{

echo "$value<BR>";

}

}

echo "<HR>";

}

}

 

// Add a site to the ring.

function approve_site($site)

{

global $submitdir, $memdir, $url, $adminmail;

$this = file("$submitdir/$site");

$data = "";

 

// Get all data from the file.

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key >= "0")

{

$value = chop($value);

if ($data == "") { $data = $value; }

else

{

$data = "$data\n$value";

}

}

}

 

// Extract details for confirmation email.

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "0")

{

$name = chop($value);

}

if ($key == "1")

{

$email = chop($value);

}

if ($key == "2")

{

$site_name = chop($value);

}

if ($key == "3")

{

$site_url = chop($value);

}

}

 

$members=opendir("$memdir");

 

// Determine the number of current members.

$files = array();

while ($file = readdir($members))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

// Add one to current and generate new ring id.

$fname = count($files) + 1;

// echo count($files);

sort($files);

$max = count($files) - 1;

$lastfile = $files[$max];

// echo $lastfile;

while ($fname <= $lastfile)

{

$fname++;

}

// echo $fname;

if ( $fp = fopen($memdir.'/'.$fname, 'w'))

{

// write the member file.

fwrite($fp, $data);

}

// Delete the file form the submissions directory.

unlink($submitdir.'/'.$site);

 

$message = "Dear $name:\n\nWe are pleased to inform you that your site, $site_name ($site_url) has been approved and added to the web ring.\n\n Please follow the URL below to find the ring code, which you should then place on your site.\n\n$url/getcode.php?id=$fname";

 

// Send confirmation email.

mail("$email", "Web Ring - Your Site Has Been Approved", $message, "From: $adminmail\nReply-To: $adminmail\nX-Mailer: PHP/" . phpversion());

 

return true;

}

 

// Echo site info into a form for editing.

function edit_site()

{

global $submitdir, $memdir, $site;

$this = file("$memdir/$site");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "0")

{

echo "Use the fomr below to edit the information for an existing site.";

echo "<HR>";

echo "<FORM ACTION=$PHP_SELF?mode=edit_confirm METHOD=POST>";

echo "<TABLE BORDER=0 CELLSPACINT=0 CELLPADDING=10>";

echo "<TR>";

echo "<TD WIDTH=80 VALIGN=TOP><B>Your Name</B></TD>";

echo "<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=name SIZE=20 VALUE=\"$value\"></TD>";

echo "</TR>";

}

 

if ($key == "1")

{

echo "<TR>";

echo "<TD WIDTH=80 VALIGN=TOP><B>Your E-Mail</B></TD>";

echo "<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=email SIZE=20 VALUE=\"$value\"></TD>";

echo "</TR>";

}

if ($key == "2")

{

echo "<TR>";

echo "<TD WIDTH=80 VALIGN=TOP><B>Site Name</B></TD>";

echo "<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=site_name SIZE=30 VALUE=\"$value\"></TD>";

echo "</TR> ";

}

if ($key == "3")

{

echo "<TR>";

echo "<TD WIDTH=80 VALIGN=TOP><B>Site URL</B></TD>";

echo "<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=site_url SIZE=30 VALUE=\"$value\"></TD>";

echo "</TR>";

}

if ($key == "4")

{

echo "<TR>";

echo "<TD WIDTH=80 VALIGN=TOP><B>Description:</B></TD>";

echo "<TD VALIGN=TOP><TEXTAREA NAME=description ROWS=5 COLS=25>";

echo $value;

}

if ($key > "4")

{

echo $value;

 

}

}

echo "</TEXTAREA></TD></TR>";

echo "<TR>";

echo "<INPUT TYPE=HIDDEN NAME=id VALUE='$site'>";

echo "<TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE=Submit NAME=Submit VALUE=Submit></TD>";

echo "</TR>";

echo "</TABLE>";

}

 

// Write updated info to the member file.

function edit_confirm($name, $email, $site_name, $site_url, $description, $id)

{

 

global $submitdir, $memdir, $name, $email, $site_name, $site_url, $description, $id;

$data = "$name\n$email\n$site_name\n$site_url\n$description";

 

if ( $fp = fopen($memdir.'/'.$id, 'w'))

{

fwrite($fp, $data);

}

 

return true;

}

 

// Just remove the file from the member directory.

function delete_site($site)

{

global $memdir, $site;

unlink($memdir.'/'.$site);

return true;

}

 

// When a site doesn't get added....

function reject_site($site)

{

global $submitdir, $memdir, $site, $url, $adminmail;

$this = file("$submitdir/$site");

$data = "";

// Extract info for denial email.

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "0")

{

$name = chop($value);

}

if ($key == "1")

{

$email = chop($value);

}

if ($key == "2")

{

$site_name = chop($value);

}

if ($key == "3")

{

$site_url = chop($value);

}

}

unlink($submitdir.'/'.$site);

 

$message = "Dear $name:\n\nWe regret to inform you that your site, $site_name ($site_url) was declied entry into the web ring.";

 

// Send message denying application.

mail("$email", "Web Ring - Your Application Has Been Denied", $message, "From: $adminmail\nReply-To: $adminmail\nX-Mailer: PHP/" . phpversion());

 

}

 

// Redirect to a random site.

function random_site()

{

global $memdir, $id;

 

srand((double) microtime() * 1000000);

 

$members=opendir("$memdir");

 

$files = array();

while ($file = readdir($members))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

$max = count($files);

if ($max == '1')

{

$name = '1';

}

else

{

$name = rand(1,$max);

}

$this = file("$memdir/$name");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "3")

{

header("Location: $value");

}

}

}

 

// Redirect to the next site in the list.

function go_next($id)

{

global $memdir, $id;

 

srand((double) microtime() * 1000000);

 

$members=opendir("$memdir");

 

$files = array();

while ($file = readdir($members))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

$max = count($files);

if ($id == $max)

{

// If the user is coming from the last site in the list, next becomes first.

$name = '1';

}

else

{

// Otherwise, we just add one to the id.

$name = $id + 1;

}

$this = file("$memdir/$name");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "3")

{

header("Location: $value");

}

}

}

 

// Go to the previous site in the list.

function go_prev($id)

{

global $memdir, $id;

 

srand((double) microtime() * 1000000);

 

$members=opendir("$memdir");

 

$files = array();

while ($file = readdir($members))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

$max = count($files);

if ($id == '1')

{

// If the user is coming from the first site in the list, then prev becomes last.

$name = $max;

}

else

{

// Otherwsie we subtract one to get the new id.

$name = $id - 1;

}

$this = file("$memdir/$name");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "3")

{

header("Location: $value");

}

}

}

 

// List all sites in the ring. -- Identical to show_members() only displays less info.

function list_all()

{

global $submitdir, $memdir;

$members=opendir("$memdir");

echo "<HEAD><TITLE>WebRing</TITLE><LINK REL=STYLESHEET HREF=style.css></HEAD>";

echo "<DIV CLASS=headline>Web Ring Index</DIV>";

echo "<DIV CLASS=normal><B>Listing All Sites</B><HR>";

$files = array();

while ($file = readdir($members))

{

if ($file != "." && $file != "..")

{

$files[] = $file;

}

}

 

for (reset ($files); list ($key, $value) = each ($files); )

{

$name = $value;

$this = file("$memdir/$value");

for (reset ($this); list ($key, $value) = each ($this); )

{

if ($key == "2")

{

$title = $value;

}

if ($key == "3")

{

echo "<B><A HREF=$value TARGET=_New>$title</A></B><BR>";

}

if ($key >= "4")

{

echo "$value<BR>";

}

}

echo "<HR>";

}

}

 

?>

 

getcode.php

 

<HEAD>

<TITLE>WebRing</TITLE>

<LINK REL=STYLESHEET HREF=style.css>

</HEAD>

<BODY>

<? require("config.php"); ?>

<DIV CLASS=headline>Get Ring Code</DIV>

<DIV CLASS=Normal>Copy and paste the code below onto your web page, where you want the ring to appear.

<HR>

<DIV ALIGN=CENTER><BR>

[<A HREF=<? echo $url; ?>><? echo $ring_name; ?> Home</A>]<BR><BR>

[<A HREF=<? echo $url; ?>/goring.php?action=prev&id=<? echo $id;?>>Prev</A>] <BR>

[<A HREF=<? echo $url; ?>/goring.php?action=rand>Random</A>] <BR>

[<A HREF=<? echo $url; ?>/goring.php?action=all>List All</A>] <BR>

[<A HREF=<? echo $url; ?>/goring.php?action=next&id=<? echo $id; ?>>Next</A>]<BR>

</DIV><BR>

</DIV>

 

goring.php

 

<?

 

require("config.php");

require("functions.php");

 

if ($action == "rand")

{

global $id;

random_site();

}

 

if ($action == "next")

{

global $id;

go_next($id);

}

 

if ($action == "prev")

{

global $id;

go_prev($id);

}

 

if ($action == "all")

{

list_all();

}

 

?>

index.php

 

<HEAD>

<TITLE>WebRing</TITLE>

<LINK REL=STYLESHEET HREF=style.css>

</HEAD>

<BODY>

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=450>

<TR>

<TD WIDTH=450>

<DIV CLASS=headline>Join The Ring</DIV>

<DIV CLASS=Normal>

 

<?

 

require("config.php");

 

if (!isset($mode))

{

$mode = 'index';

}

 

switch($mode)

{

 

case 'index':

 

?>

 

If you would like to join the webring, simply fill out the fomr below. Please note that it may take up to 48 hours for your site to be approved, depending on how busy we are.

<HR>

 

<FORM ACTION=<? echo $PHP_SELF; ?>?mode=submit METHOD=POST>

 

<TABLE BORDER=0 CELLSPACINT=0 CELLPADDING=10>

<TR>

<TD WIDTH=80 VALIGN=TOP><B>Your Name</B></TD>

<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=name SIZE=20></TD>

</TR>

<TR>

<TD WIDTH=80 VALIGN=TOP><B>Your E-Mail</B></TD>

<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=email SIZE=20></TD>

</TR>

<TR>

<TD WIDTH=80 VALIGN=TOP><B>Site Name</B></TD>

<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=site_name SIZE=30></TD>

</TR>

<TR>

<TD WIDTH=80 VALIGN=TOP><B>Site URL</B></TD>

<TD VALIGN=TOP><INPUT TYPE=TEXT NAME=site_url SIZE=30 VALUE='http://'></TD>

</TR>

<TR>

<TD WIDTH=80 VALIGN=TOP><B>Description:</B></TD>

<TD VALIGN=TOP><TEXTAREA NAME=description ROWS=5 COLS=25></TEXTAREA></TD>

</TR>

<TR>

<TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE=Submit NAME=Submit VALUE=Submit></TD>

</TR>

</TABLE>

 

<?

break;

 

case 'submit':

 

require("functions.php");

 

$submit = submit_site($name, $email, $site_name, $site_url, $description);

 

if ($submit == 'true')

{

echo "Your submission has been added. Thank you.";

}

 

else

{

echo "There was an error in processing your application. Please be sure you filled out all of the fields.";

}

 

echo "<HR><A HREF=$PHP_SELF?mode=index>Go Back</A>";

}

 

?>

</DIV>

</TD>

</TR>

</TABLE>

 

 

smtpmail

 

<?

 

// These functions may be used as a replacement for PHP's

// built-in mail() function, which doesn't work in all servers.

// Include this file, then replace PHP's mail(); function with:

 

// $subject = ""; /* The message subject */

// $message = ""; /* The message */

 

// $FromUser = ""; /* Your email address */

// $ToUser = ""; /* Recipent's email */

// $SMTPServer = ""; /* Your SMTP server */

 

// $mail = smtp_open($SMTPServer, 25);

// smtp_helo($mail);

// smtp_mail_from($mail, $FromUser);

// smtp_rcpt_to($mail, $ToUser);

 

// smtp_data($mail, $subject, $message);

// smtp_quit($mail);

 

function smtp_open($server, $port)

{

global $SMTP_GLOBAL_STATUS;

 

$smtp = fsockopen($server, $port);

if ($smtp < 0) return 0;

 

$line = fgets($smtp, 1024);

 

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

 

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

 

return $smtp;

}

 

 

function smtp_helo($smtp)

{

global $SMTP_GLOBAL_STATUS;

 

/* 'localhost' always works */

fputs($smtp, "helo localhost\r\n");

$line = fgets($smtp, 1024);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

 

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

 

return 1;

}

 

function smtp_mail_from($smtp, $from)

{

global $SMTP_GLOBAL_STATUS;

 

fputs($smtp, "MAIL FROM: <$from>\r\n");

$line = fgets($smtp, 1024);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

 

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

 

return 1;

}

 

function smtp_rcpt_to($smtp, $to)

{

global $SMTP_GLOBAL_STATUS;

 

fputs($smtp, "RCPT TO: <$to>\r\n");

$line = fgets($smtp, 1024);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

 

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

 

 

return 1;

}

 

function smtp_data($smtp, $subject, $data)

{

global $SMTP_GLOBAL_STATUS;

 

fputs($smtp, "DATA\r\n");

$line = fgets($smtp, 1024);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

 

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "3") return 0;

 

fputs($smtp, "Mime-Version: 1.0\r\n");

fputs($smtp, "Subject: $subject\r\n");

fputs($smtp, "$data\r\n\r\n");

fputs($smtp, ".\r\n");

$line = fgets($smtp, 1024);

if (substr($line, 0, 1) <> "2")

return 0;

 

return 1;

}

 

function smtp_quit($smtp)

{

global $SMTP_GLOBAL_STATUS;

 

fputs($smtp, "QUIT\r\n");

$line = fgets($smtp, 1024);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] = substr($line, 0, 1);

$SMTP_GLOBAL_STATUS[$smtp]["LASTRESULTTXT"] = substr($line, 0, 1024);

 

if ($SMTP_GLOBAL_STATUS[$smtp]["LASTRESULT"] <> "2") return 0;

 

return 1;

}

 

?>

Link to comment
Share on other sites

D-Ring README

D-Ring README

--------------------------------------------------------------

 

 

#########################################################

# #

# PHPSelect Web Development Division #

# #

# http://www.phpselect.com/ #

# #

# This script and all included modules, lists or #

# images, documentation are distributed through #

# PHPSelect (http://www.phpselect.com/) unless #

# otherwise stated. #

# #

# Purchasers are granted rights to use this script #

# on any site they own. There is no individual site #

# license needed per site. #

# #

# This and many other fine scripts are available at #

# the above website or by emailing the distriuters #

# at admin@phpselect.com #

# #

#########################################################

 

 

1. Introduction

2. License

3. Configuring & Installing

4. Troubleshoting

5. Contacting Me

--------------------------------------------------------------

1. Introduction

--------------------------------------------------------------

D-Ring is a simple web ring script written in PHP4 that allows

you to run a web ring on your site, without the need of third

party servers, like webring.org or yahoo. It is meant to be

easy to install and use, though you will be required to set a

couple of variables.

 

NOTE: No user authentication or protection is in place for the

admin section of the script, so you will need to either write

your own, or use a .htaccess/.htpasswd combo, which is what I

did.

--------------------------------------------------------------

2. License

--------------------------------------------------------------

D-Ring is distributed under the terms and conditions of the

GNU General Public License (GPL) version 2.0 (or, at your

discretion, any later version). You are free to moify and

redistribute copies of this script in accordance with the

terms contained within the GPL.

--------------------------------------------------------------

3. Configuring & Installing

--------------------------------------------------------------

In order to configure the script to work on your server, first

unzip all of the files into a folder on your hard drive. Next,

open config.php and set the variables as instructed.

 

Note: If you change the values of $submitdir and $memdir,

they MUST be absolute paths. Also, you must manually

create these directories. (This is done so that the

script may be used on servers which run PHP in safe mode)

 

Upload all of the files to your website, and CHMOD the

"incoming" directory and the "members" directory to 777.

 

That's it! If you paths and permissions have been set properly

then you're in business and your webring is now ready to use.

 

You may wish to take steps to password protect the index.php

file in the admin/ directory. I highly reccommended that you do

so!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...