Mithrandir (post: 1372785) wrote:It seems like you really want a database back-end to store the data, a php script to query it, and an HTML output to the end user. There are probably dozens of open source scripts to do exactly what you're saying, but if you want to roll your own, it shouldn't be too hard. What kind of database do you have access to (if any)?
<?php
// Author: PHPFront.com © 2005
// License: Free (GPL)
//
// Version: 1.1
//
// Created: 8.12.2005
//
// More information and downloads
// available at http://www.PHPFront.com
//
// #### poll.php ####
include("admincp/config.php");
$user_ip = $_SERVER['REMOTE_ADDR'];
$ipquery = mysql_query("SELECT * FROM fpoll_ips WHERE ip='$user_ip'");
$select_banned = mysql_num_rows($ipquery);
if($select_banned){
//display results
$poll = mysql_fetch_array(mysql_query("select * from fpoll_poll"));
$question = $poll['question'];
$countvotes = mysql_query("select votes from fpoll_options");
while ($row = mysql_fetch_assoc($countvotes)) {
$totalvotes += $row["votes"];
}
echo("<div class=poll>$question
");
$get_questions = mysql_query("select * from fpoll_options");
while($r=mysql_fetch_array($get_questions)){
extract($r);
$per = $votes * 100 / $totalvotes;
$per = floor($per);
echo htmlspecialchars($field);
?> <strong><? echo("$votes"); ?></strong>
<div style="background-color: <? echo config(bg1); ?>;"><div style="color: <? echo config(text); ?>; font-size: <? echo config(size); ?>px; text-align: right;background-color: <? echo config(bg2); ?>; width: <? echo($per); ?>%;"><? echo("$per%"); ?></div></div>
<?
}
echo("
Total votes: <strong>$totalvotes</strong></div>");
}else{
//if the submit button was pressed
if($_POST['submit']){
//grab vars
$vote = $_POST['vote'];
$refer = $_POST['refer'];
//update numbers
$update_totalvotes = "UPDATE fpoll_poll SET totalvotes = totalvotes + 1";
$insert = mysql_query($update_totalvotes);
$update_votes = "UPDATE fpoll_options SET votes = votes + 1 WHERE id = $vote";
$insert = mysql_query($update_votes);
//add ip to stop multiple voting
$ip = $_SERVER['REMOTE_ADDR'];
$addip = mysql_query("INSERT INTO fpoll_ips (ip)". "VALUES ('$ip')");
//send the user back to thepage they were just viewing
header("Location: $refer");
}
$uri = $_SERVER['REQUEST_URI'];
//display the form!
?><div class="poll"><form action="/Fpoll/poll.php" method="post"><?
$poll = mysql_fetch_array(mysql_query("select * from fpoll_poll"));
$question = $poll['question'];
echo("$question
");
$getcurrent = mysql_query("select * from fpoll_options ORDER by id");
while($r=mysql_fetch_array($getcurrent)){
extract($r);
?><input type="radio" name="vote" value="<? echo($id); ?>" class="radiobutton" /> <? echo($field); ?>
<?
}
?>
<input type="hidden" name="refer" value="<? echo $_SERVER['PHP_SELF']; ?>" />
<input type="submit" name="submit" value="Submit" />
</form></div>
<?
}
?>
<?
phpinfo();
?>
<script language="php">
phpinfo();
</script>
<?PHP
phpinfo();
?>
print <<<EOF
<p>this is some html</p>
EOF;
<form method="post" action="post.php">
<table>
<tr><td>Username:</td><td><input type="text" name="username" /></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" /></td></tr>
<tr><td align="center"><input type="submit" name="login" value="Log In" /></td></tr>
</table>
</form>
<?php
session_start();
$user = "YourName";
$pass = "yourpass";
if($_POST['username'] == $user & $_POST['password'] == $pass)
{
$_SESSION['logged_in'] = "true";
$_SESSION['username'] = $_POST['username'];
echo('<meta name="refresh" content="0; url=page.php" />');
}
if(!isset($_SESSION['logged_in']))
{
echo('You must log in to view this page.
<a href="login.html">Click here</a> to log in.');
}
else
{
?>
<?php
$usern = $_SESSION['username'];
$title = $_POST["title"];
$post = $_POST["post"];
if (!isset($_POST['submit'])) {
?>
<html>
<head>
<title>Create Entry</title>
</head>
<body>
<?php
echo "You are logged in as:
<b>".$usern."</b>.
";
?>
<form method="post" action="<?php echo $PHP_SELF;?>">
Post Title:
<input type="text" size="36" maxlength="128" name="title">
Post Content:
<textarea rows="24" cols="100" name="post" wrap="physical"></textarea>
<input type="submit" value="Submit Post" name="submit">
</form>
<?php
} else {
$v0 = "Posted by <b>".$usern."</b> on ".date("F dS, Y @ h:i:sa").".";
$v1 = "".$title.".";
$v2 = "$post";
$file = "post.txt";
$values = "$v0\r\n $v1\r\n $v2\r\n";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
$numBytes = fwrite($fp, $values) or die("Couldn't write values to file!");
fclose($fp);
echo "Wrote $numBytes bytes to $file successfully!";
}
?>
<?php
}
?>
<?php
session_start();
$usernames = array("user1", "user2", "user3", "admin");
$passwords = array("pass1", "pass2", "pass3", "");
for($i=0;$i<count($usernames);$i++){
$logindata[$usernames[$i]]=$passwords[$i];
}
{
$_SESSION['logged_in'] = "true";
$_SESSION['username'] = $_POST['username'];
echo('<meta name="refresh" content="0; url=post.php" />');
}
if(!isset($_SESSION['logged_in']))
{
echo('You must log in to view this page.
<a href="login.html">Click here</a> to log in.');
}
else
{
?>
<?php
$usern = $_SESSION['username']; \\Here, I create $usern to display the user's login name both in the form and in the data file to be displayed on the front page.
$title = $_POST["title"];
$post = $_POST["post"];
if (!isset($_POST['submit'])) {
?>
<html>
<head>
<title>Create Entry</title>
</head>
<body>
<table align="center" border="0">
<tr>
<td>
<form method="post" action="<?php echo $PHP_SELF;?>">
Post Title:
<input type="text" size="36" maxlength="128" name="title">
</td>
<td align="center">
<?php echo "You are logged in as:
<b>".$usern."</b>
";?> \\$usern works fine here, but..
</td>
</tr>
<tr>
<td colspan="2">
Post Content:
<textarea rows="10" cols="67" name="post" wrap="physical"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit Post" name="submit">
</td>
<td>
<a href="logout.php">Click here to log out and go back to the main page.</a>
</td>
</form>
</td>
</tr>
</table>
</body>
</html>
<?php
} else {
$v0 = "Posted by <b>".$usern."</b> on ".date("F dS, Y @ h:i:sa").".";
$v1 = "$title";
$v2 = "$post";
$file = "post.txt";
$old = file_get_contents($file, 1);
$v3 = str_replace(array("\r\n", "\r", "\n"), "
", $v2);
$values = '
<!--POST BEGIN-->
<tr>
<td align="center" valign="top">
<img src="img/avatar100.jpg" class="avatar">
</td>
<td align="left">
<font size="8" class="ptitle">'.$v1.'</font>
<font size="2" align="right">'.$v0.'</font> \\Somewhere before here, $usern gets eaten. why?
</td>
</tr>
<tr>
<td>
</td>
<td>
<p class="post">'.$v3.'</p>
</td>
</tr>
<!--POST END-->'.$old.'';
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
$numBytes = fwrite($fp, $values) or die("Couldn't write values to file!");
fclose($fp);
echo '[align=center]News article posted successfully!
Click <a href="logout.php">here</a> to log out and return
to the main page. [/align]';
}
?>
<?php
}
?>
$in-user = $_REQUEST{username};
$in-pass = $_REQUEST{password};
$user_array = array(
'user1' => 'pass1',
'user2' => 'pass2',
'user3' => 'pass3'
);
if ($user_array{$in-user} == $in-pass)
{
# is valid user
}
else
{
# is not valid user
}
$salt = 'some random text 78sdga698ags987asg90';
$in-pass = $_REQUEST{password};
$encrypted_password = md5($salt . $in-pass);
$d0 = "post/p0.txt";
$d1 = "post/p1.txt";
$d2 = "post/p2.txt";
$d3 = "post/p3.txt";
$d4 = "post/p4.txt";
$d5 = "post/p5.txt";
$d6 = "post/p6.txt";
$d7 = "post/p7.txt";
$d8 = "post/p8.txt";
$d9 = "post/p9.txt";
$ar = "post/archive.txt";
$n0 = file_get_contents($d0, 1);
$n1 = file_get_contents($d1, 1);
$n2 = file_get_contents($d2, 1);
$n3 = file_get_contents($d3, 1);
$n4 = file_get_contents($d4, 1);
$n5 = file_get_contents($d5, 1);
$n6 = file_get_contents($d6, 1);
$n7 = file_get_contents($d7, 1);
$n8 = file_get_contents($d8, 1);
$n9 = file_get_contents($d9, 1);
$na = file_get_contents($ar, 1);
$v0 = ''.$n0.'';
$v1 = ''.$n1.'';
$v2 = ''.$n2.'';
$v3 = ''.$n3.'';
$v4 = ''.$n4.'';
$v5 = ''.$n5.'';
$v6 = ''.$n6.'';
$v7 = ''.$n7.'';
$v8 = ''.$n8.'';
$v9 = ''.$n9.'';
$var = ''.$n9.'
'.$na.'';
$fp10 = fopen($ar, "w") or die("Couldn't open $start for writing!");
fwrite($fp10, $var) or die("Couldn't write values to file!");
fclose($fp10);
$fp9 = fopen($d9, "w") or die("Couldn't open $start for writing!");
fwrite($fp9, $n8) or die("Couldn't write values to file!");
fclose($fp9);
$fp8 = fopen($d8, "w") or die("Couldn't open $start for writing!");
fwrite($fp8, $n7) or die("Couldn't write values to file!");
fclose($fp8);
$fp7 = fopen($d7, "w") or die("Couldn't open $start for writing!");
fwrite($fp7, $n6) or die("Couldn't write values to file!");
fclose($fp7);
$fp6 = fopen($d6, "w") or die("Couldn't open $start for writing!");
fwrite($fp6, $n5) or die("Couldn't write values to file!");
fclose($fp6);
$fp5 = fopen($d5, "w") or die("Couldn't open $start for writing!");
fwrite($fp5, $n4) or die("Couldn't write values to file!");
fclose($fp5);
$fp4 = fopen($d4, "w") or die("Couldn't open $start for writing!");
fwrite($fp4, $n3) or die("Couldn't write values to file!");
fclose($fp4);
$fp3 = fopen($d3, "w") or die("Couldn't open $start for writing!");
fwrite($fp3, $n2) or die("Couldn't write values to file!");
fclose($fp3);
$fp2 = fopen($d2, "w") or die("Couldn't open $start for writing!");
fwrite($fp2, $n1) or die("Couldn't write values to file!");
fclose($fp2);
$fp1 = fopen($d1, "w") or die("Couldn't open $start for writing!");
fwrite($fp1, $n0) or die("Couldn't write values to file!");
fclose($fp1);
$fp0 = fopen($d0, "w") or die("Couldn't open $start for writing!");
fwrite($fp0, $new) or die("Couldn't write values to file!");
fclose($fp0);
$post_count = 10;
$ar = 'post/archive.txt';
$na = file_get_contents($ar, 1);
$d = array();
$n = array();
$v = array();
for($post_index = 0; $post_index < $post_count; $post_index++) {
$d[$post_index] = 'post/p' . $post_index . '.txt';
$n[$post_index] = file_get_contents($d[$post_index], 1);
$v[$post_index] = '' . $n[$post_index] . '';
}
$var = '' . $n[$post_count] . '' . $na . '';
$fp = array();
$fp[$post_count] = fopen($ar, "w") or die("Couldn't open $start for writing!");
fwrite($fp[$post_count], $var) or die("Couldn't write values to file!");
fclose($fp[$post_count]);
for($post_index = $post_count - 1; $post_index > 0; $post_index--) {
$fp[$post_index] = fopen($d[$post_index], "w") or
die("Couldn't open $start for writing!");
fwrite($fp[$post_index], $n[$post_index - 1]) or
die("Couldn't write values to file!");
fclose($fp[$post_index]);
}
$fp[0] = fopen($d[0], "w") or die("Couldn't open $start for writing!");
fwrite($fp[0], $new) or die("Couldn't write values to file!");
fclose($fp[0]);
Users browsing this forum: No registered users and 127 guests