PDA

View Full Version : Allow authorized user to change text on webpage *SOLVED* Please comment


JasonDFR
04-08-2008, 05:13 PM
I would like to be able to allow someone to change one line of text on an HTML document that I constructed. It needs to be password protected.

For example:

HTML: <span>We will be open Monday</span> is on www.mysite.com . I would like to create a page where there is a form box that a user can enter text into, click a submit button, and have "We will be open Monday" change to whatever they want. This would then be saved so subsequent visitors would see the updated text.

Please help, I think this is pretty simple and I have found some solutions, but they are all very very complicated.

Thanks in advance. Great fourms!

Jason

hmsnacker123
04-08-2008, 05:23 PM
hmm try this: (XHTML)


<html>
<head>
<script type="text/javascript">
function refresh() {
var txt = document.getElementById('usertext').value;
document.getElementById('update').innerHTML = txt;
}
</script>
</head>
<body>
<p><span id="update">We will be open Monday</span></p>
<input type="text" id="usertext" /><input type="button" onClick="refresh()" value="Update" />
</body>
</html>

Please COntact mE!

JasonDFR
04-08-2008, 05:35 PM
Thanks. That is on the right track.

But I need something server side I think that will save the entered text into the original HTML document.

I would like to put the text box on a separate page that I will password protect.

So someone goes to www.mysite.com/private.html and enters text into the box, clicks a button. The text on www.mysite.com/index.html is changed and remains that way.

Thanks again for the help!

J

hmsnacker123
04-08-2008, 05:42 PM
ok for a login i highly recomend that you dont use JavaScript, but find a PHP script or cofigure a sql database using aspx instead as for the thing where is saves the text, you can also use aspx webparts. to download sql look on microsoft.com. reply.

also i think you should set up an IIS so you can view .aspx extensions in your web browser. (if you cant already)

JasonDFR
04-08-2008, 05:52 PM
Thanks again for the reply. I'll look into your suggestions for sure.

I just found this:

http://www.snippetmaster.com/index.php

Any thoughts on it?

hmsnacker123
04-08-2008, 05:56 PM
this cant permantly save the edited text to the website through the private.html page, but this is my last reply cos i have to go :)

JasonDFR
04-09-2008, 09:46 AM
I have spent this morning figuring it out and I came up with this. It is different from your script, but it seems to work. BTW I used the Tizag.com tutorial to learn all this. It is a really good tut.

*****I've got this where I want it on /index.php : <span><?php include("ticker.txt"); ?></span>

*****I've got this on /private.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>


</head>

<body>

<h1>TICKER CHANGE PAGE</h1>

<h2>60 Characters Maximum INCLUDING Spaces</h2>
<br />
<form action="process.php" method="post">
New Ticker Text: <input type="text" size="60" maxlength="60" name="ticker_text" />
<input type="submit" />
</form>


</body>
</html>


******And this on /process.php :


<html>

<body>

<?php

$ticker_text = $_POST['ticker_text'];

$ticker_file = "ticker.txt";
$fh = fopen($ticker_file, 'w') or die("can't open file");
fwrite($fh, $ticker_text);
fclose($fh);
echo $ticker_text;

?>

</body>

</html>


Seems to work. I'll password protect /private.php.

You guys see any flaws?

Master_script_maker
04-09-2008, 12:32 PM
here's my view of private.php(with login):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>


</head>

<body>
<?php
if ($_POST['password']=="your_pass" && $_POST['username']=="your_user") {
?>
<h1>TICKER CHANGE PAGE</h1>

<h2>60 Characters Maximum INCLUDING Spaces</h2>
<br />
<form action="process.php" method="post">
Ticker Text: <input type="text" value="<?php include('ticker.txt');?>" size="60" maxlength="60" name="ticker_text" />
<input type="submit" />
</form>
<?php
} else {
$error=(isset($_POST['submitted']) && $_POST['submitted']=="yes")?"Wrong username or password. Please try again.":"";
echo '<span style="font-color:red">'.$error.'</span><br />';
?>
<form action="private.php" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="text" name="password" />
<input type="hidden" name="submitted" value="yes"/><br />
<input type="submit" />
<?php
}
?>
</form>
</body>
</html>
change the values in red

JasonDFR
04-09-2008, 03:26 PM
Very nice. I like it. How do I handle the password in this case? I had planned to use my webhosts file manager to password protect the /private.php file .

J

bluegillmedia
05-01-2008, 02:05 AM
Did anyone get this to work? I get an 405 error, but then when i refresh it shows me nothing except for the bit of normal html text i popped in there, the word type in in private.php should show up between the brackets).

this is my process file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>


</head>

<body>

<h1>TICKER CHANGE PAGE</h1>

<h2>60 Characters Maximum INCLUDING Spaces</h2>
<br />
<form action="process.php" method="post">
New Ticker Text: <input type="text" size="60" maxlength="60" name="ticker_text" />
<input type="submit" />
</form>


</body>
</html>

I am really in desperate need of some code that an admin user can change and every other surfer will see (on a different page like the example above).

Master_script_maker
05-01-2008, 01:55 PM
admin.php:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>


</head>

<body>
<?php
if ($_POST['password']=="your_pass" && $_POST['username']=="your_user") {
?>
<h1>TICKER CHANGE PAGE</h1>

<h2>60 Characters Maximum INCLUDING Spaces</h2>
<br />
<form action="process.php" method="post">
Ticker Text: <input type="text" value="<?php include('ticker.txt');?>" size="60" maxlength="60" name="ticker_text" />
<input type="submit" />
</form>
<?php
} else {
$error=(isset($_POST['submitted']) && $_POST['submitted']=="yes")?"Wrong username or password. Please try again.":"";
echo '<span style="font-color:red">'.$error.'</span><br />';
?>
<form method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="text" name="password" />
<input type="hidden" name="submitted" value="yes"/><br />
<input type="submit" />
</form>
<?php
}
?>
</body>
</html>
process.php:
<?php

$ticker_text = $_POST['ticker_text'];

$ticker_file = "ticker.txt";
$fh = fopen($ticker_file, 'w') or die("can't open file");
fwrite($fh, $ticker_text);
fclose($fh);
echo $ticker_text;

?>
and on any html page you want the ticker text: <?php include("ticker.txt");?> e.g: <html>
<head>
</head>
<body>
<div id="ticker"><?php include("ticker.txt");?></div>
</body>
</html>