PDA

View Full Version : PHP input driving a dynamic flash site(issues)


SpiderArts
07-07-2005, 01:50 AM
uhg...im not a php person so i had one my my programmers at work write this. And it works GREAT at work but for some JACKED up reason it doesnt work great from home. Maybe you guys can help me out.
I have a flash website, that loads its text dynamicaly from a text file.
The text file it reads from is a text file generated by a php page.
The page itself has a bunch of input fields and the idea is that you can input the text easily into those fields and have it update the flash site.

The following is a ton of code...

<?php
session_start();
if(!$_SESSION['user'] && !$_POST['user'])
{
print("
<form name=stdform method=post>
<center>
<table>
<tr>
<td>
Username:
</td>
<td>
<input name=user>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type=password name=password>
</td>
</tr>
<tr>
<td COLSPAN=10 ALIGN=CENTER>
<input type=submit value=Login>
</td>
</tr>
</table>
</center>
</form>
");
exit(0);
}
else if($_POST['user'])
{
$user=$_POST['user'];
$password=$_POST['password'];
if($password!="arts" || $user !="spider")
{
print("<form name=stdform method=post>
<center>
<table>
<tr>
<td COLSPAN=10 ALIGN=CENTER>
Password or user incorrect, please try again.
</td>
</tr>
<tr>
<td>
Username:
</td>
<td>
<input name=user>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type=password name=password>
</td>
</tr>
<tr>
<td COLSPAN=10 ALIGN=CENTER>
<input type=submit value=Login>
</td>
</tr>
</table>
</center>
</form>");
exit(0);
}
$_SESSION['user']="root";
}
else if($_REQUEST['logout'])
{
$_SESSION = array();
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', time()-42000, '/');
}
// Destroy current session
session_destroy();
print("<CENTER>You have been logged out.<br>Click <a href=index.php>here</a> to log in.</CENTER>");
exit(0);
}
$output_file="content.txt";
$fields[]="Main Page";
$names[]="content1";
$fields[]="Products";
$names[]="content2";
$fields[]="Tidal Force";
$names[]="content3";
$fields[]="Wave Crest";
$names[]="content4";
$fields[]="Contact Us";
$names[]="content5";

$fp=fopen("$output_file","r");
while(($field=fread_word($fp))!="")
{
$i=get_index($field,$names);
if($i==-1)
{
$value=fread_block($fp);
$extra_text.="&$field=$value";
}
else
$values[$i]=fread_block($fp);
}
fclose($fp);
$field=str_replace(" ","_",$fields[0]);
if(!$_POST["$field"])
{
print("<html>
<body>
<form name=stdform method=post>
<input type=hidden name=extra_text value=\"$extra_text\">
<center>
<table>
<tr>
<td colspan=10 align=center>
<a href=index.php?logout=true>Logout</a>
</td>
</tr>");
$i=0;
foreach($fields as $field)
{
$value=$values[$i];
$i++;
print("
<tr>
<td>
$field
</td>
<td>
<textarea name='$field' rows=5 cols=60>$value</textarea>
</td>
</tr>");
}

print("
<tr>
<td colspan=2 align=center>
<input type=submit value=Submit>
</td>
</tr>
</table>
</center>
</form>
</body>
</html>");
}
else
{
$fp=fopen($output_file,"w");
$i=-1;
foreach($_POST as $p)
{
if($i>=0)
{
$field=$names[$i];
fprintf($fp,"&%s=%s",$field,$p);
}
$i++;
}
$field=$_POST['extra_text'];
fprintf($fp,"$field");
header("Location: index.php");
}
function get_index($field_name, $fields)
{
$i=0;
foreach($fields as $field)
{
if($field == $field_name)
return $i;
$i++;
}
return -1;
}
function fread_word($fp)
{
$c="";
while(!feof($fp) && (($c=fgetc($fp))==" " || $c=="=" || $c=="&"))
;
if(!feof($fp)) fseek($fp,-1,SEEK_CUR);
if(feof($fp)) return "";

while(!feof($fp) && ($c=fgetc($fp))!= " " && $c!="=" && $c!="&")
{
$line.=$c;
}
while(!feof($fp) && (($c=fgetc($fp))=="&"))
;
if(!feof($fp)) fseek($fp,-1,SEEK_CUR);
return $line;
}
function fread_line($fp)
{
$c=" ";
while(!feof($fp) && (($c=fgetc($fp))=="&"))
;
if(!feof($fp)) fseek($fp,-1,SEEK_CUR);
if(feof($fp)) return "";

while(!feof($fp) && ($c=fgetc($fp))!="&")
{
$line.=$c;
}
while(!feof($fp) && (($c=fgetc($fp))=="&"))
;
if(!feof($fp)) fseek($fp,-1,SEEK_CUR);
return $line;
}
function fread_block($fp)
{
$c=" ";
while(!feof($fp) && (($c=fgetc($fp))=="&"))
;
if(!feof($fp)) fseek($fp,-1,SEEK_CUR);
if(feof($fp)) return "";

while(!feof($fp) && ($c=fgetc($fp))!="&")
{
$line.=$c;
}
while(!feof($fp) && (($c=fgetc($fp))=="&"))
;
if(!feof($fp)) fseek($fp,-1,SEEK_CUR);
return $line;
}
?>

So thats the php file. It does a great job reading the current content.txt but when i try to submit new changes it clears the content.txt file completely.

Thanx for your help

jerryj
07-07-2005, 09:56 AM
Hi SpiderArts,

yes it is funny, I meant something like this in my thread (and I am not trying to crosspost here!! :p ).

What do you mean with 'from home'?
You are aware of the fact that you need a php enabled server? Which your local machine/server isn't by default.

But I will surely look at this code, very interesting,

Jerryj.

SpiderArts
07-07-2005, 04:31 PM
yeah im aware, i host it on my webserver. Which has php enabled...ive got a programmar on it right now....something about the fprintf command isnt working. We Might have it nailed down here in about 5 minutes. Feel free to use that code if ya need it.

PS from home means not at work. We wrote the file at work. I uploaded it at home.