Hi, I was wondering for my radio if it was possible to overwrite a page for example a DJSays?
For example:
If the DJ types in the textrea box:
| Quote: |
| Hey Listeners! DJ Whomever here! Playing music 24/7! |
then on djsays.php it would erase whats in djsays.php and put the above quote.
Does anybody have a php code for this??
Thanks!
you could do it off using php and mysql where whatever he says gets updated into the database and on the djsays.php it does a search for whatever is in the database and echoes it. That might not be a great explanation so if you want it explained better with code then i will show you.
I know it is possible with php, but I just don't know how..and I think there is a easier way then using mysql. I was thinking of when the DJ enters the text it replaces it in a .html or .php file..
Any ideas?
ok i dont think i know how to do it without php.
No yournot understanding.. when the DJ enters the replacement text it replaces what ever is in djsays.php. Any other ideas?
I think it's better to use a database, otherwise you have to make the file rewritable which could reduce security... just go for the database! 
Actully now thinking about that, couldn't I keep the mysql databases to log files?
Hmm.. still wondering how to write this..
Also on zymic.com they told me to use fopen and fwrite using flat files.
So help me again!
Thx!
| Code: |
<?php
$fp = fopen('editsays.php', 'w');
echo '
<form>
<input type="text" name="djsays"><BR>
<input type="submit" value="DJ Says">
</form>';
fwrite($fp, 'djsays');
fclose($fp);
?> |
Hi, again... I learned a little bit of fopen and fwrite.. so, when I go to djsays.php I get the textrea, but when I press DJ Says it refreshes and nothing goes into the editsays.php but "DJSAYS" so somehow I need to get what the DJ puts into the textbox and then it goes into editsays.php..
Any ideas?
I have an idea I should be able to script it. It is very simple think to do come back in half an hour or an hour I should have it coded then.
As I said I would have your script well here it is I will give you a little lessong on whats going on here.
Ok first you want to open up your favourite html editor (ex. NotePad) Now put this code into it:
| Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Create A File</title>
</head>
<body>
<form name="input" method="post"
action="<?php echo $_SERVER['SCRIPT_NAME']?>">
<p><label for="dj">DJSays: </label>
<input type="text" name="djsays" id="dj" /></p>
You can use html tags to format the text as long as they don't use the ="" (ex. <font color="green">
<p><input type="reset" name="reset" value="reset" />
<input type="submit" name="submit" value="submit" /></p>
</form>
<?php
if (isset($_POST['submit'])) {
$djsays = $_POST['djsays'];
$fp = fopen("djsays.html","w");
if(!$fp) {
echo 'Error, the file could not be opened or there was an error creating it.';
exit;
}
fwrite($fp, $djsays."");
}
?>
</body>
</html>
|
Now lets look at what is going on so the first part before the <php? tag is just the form the stuff that will appear on the edit page. This page is for creating/overwriting the file we will save what dj says to. Lets look at the php involved section:
| Code: |
<?php
if (isset($_POST['submit'])) {
$djsays = $_POST['djsays'];
$fp = fopen("djsays.html","w");
if(!$fp) {
echo 'Error, the file could not be opened or there was an error creating it.';
exit;
}
fwrite($fp, $djsays."");
}
?>
|
Ok so $djsays = $_POST['djsays']; is just loading the variable that is the collected information from the form and turning its operating word I guess you could say to $djsays now with $fp = fopen("djsays.html","w");
we open the file djsays.html the w says open it for writing and overwrite anything in it and if it doesn't exist try and create it. Last fwrite($fp, $djsays.""); says to write the variable $djsays to the file. Remember to save this file with a .php extension.
Next create the page for people to read what djsays. Here is the code for that page:
| Code: |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content=10>
<title>HomePage</title>
</head>
<body>
Lets here what the DJ has to say today:<br /><br />
<iframe
src ="djsays.html"
width="100%" scrolling="no">
</iframe>
</body>
</html>
|
At the top in this: <meta http-equiv="refresh" content=10> this causes the page to refresh every 10 seconds. Now this :<iframe
src ="djsays.html"
width="100%" scrolling="no"> is an iframe loading the page djsays.html which is the page that was created/overwrited in the first script. Which inturn loads what the dj sayed on the page.
If you don't want the hole page to refresh you can create another file that is plane with an iframe in it of djsays.html and just have the iframe in the first page to link to that page. Then you would only have the iframe refresh.
One last thing remember to chmod the folder that you are putting djsays.html in to 777.
DUDE, I OWE YOU SO FING MUCH! THANK YOU!
Dude NP glad to help, had nothing to do anyways i was waiting for someone to figure out my problem with the FCKeditor.