Fwrite to certain area on a page

This is a discussion on "Fwrite to certain area on a page" within the PHP Forum section. This forum, and the thread "Fwrite to certain area on a page are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 31st, 2007, 18:32
Reputable Member
Join Date: Jan 2004
Location: California
Age: 19
Posts: 232
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via AIM to tox0tes
Fwrite to certain area on a page

Here is my problem: I have a page called install.php that is just a user entry form. Each textfield is associated with a string on another page, variables.php. I want people to be able to type in a value in the text field and have that value fwrited to the value of the string on the other page. Is this possible?
Reply With Quote

  #2 (permalink)  
Old Aug 31st, 2007, 18:40
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Fwrite to certain area on a page

Can be done with classes like i said
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Aug 31st, 2007, 19:09
Reputable Member
Join Date: Jan 2004
Location: California
Age: 19
Posts: 232
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via AIM to tox0tes
Re: Fwrite to certain area on a page

I do have classes. I have it all set up to do this, but I am having a little problem with the strings actually executing before they are fwrited to the variables.php page.

Here is install.php (only the strings siteurl and password are being utilized) (variables.txt is a blank text file):
PHP: Select all

<?php
if($_POST['Submit']){
$open "variables.txt";
$fh fopen($open'a') or die("can't open file");
$siteurl1 $_POST['siteurl'];
fwrite($fh"$siteurl = '".$siteurl1."';\n");
$password1 $_POST['password'];
fwrite($fh"$password = '".$password1."';\n");
fclose($fh);
echo 
"Changes Saved.";
}else{
echo 
"<form action='".$PHP_SELF."' method='post'>Web Site URL (i.e. http://www.yoursite.com)<input id='siteurl' name='siteurl' type='text'><br>Make up a password <input id='password' name='password' type='text'><br><br><table cellpadding='0' cellspacing='0'><tr><td valign='top'>Page 1 without extension (i.e. home)<input id='page1' name='page1' type='text'><br>Page 2 without extension (i.e. about)<input id='page2' name='page2' type='text'><br>Page 3 without extension (i.e. history)<input id='page3' name='page3' type='text'><br>Page 4 without extension (i.e. directions)<input id='page4' name='page4' type='text'><br>Page 5 without extension (i.e. gallery)<input id='page5' name='page5' type='text'><br>Page 6 without extension (i.e. products)<input id='page6' name='page6' type='text'><br>Page 7 without extension (i.e. downloads)<input name='page7' type='text'><br>Page 8 without extension (i.e. forums)<input name='page8' type='text'><br>Page 9 without extension (i.e. prices)<input name='page9' type='text'><br>Page 10 without extension (i.e. contact)<input name='page10' type='text'></td><td valign='top'><br>Name of image folder 1 (i.e. art)<input name='pics1directory' type='text'><br>Name of image folder 2 (i.e. people)<input name='pics2directory' type='text'><br>Name of image folder 3 (i.e. places)<input name='pics3directory' type='text'></td></tr></table><input name='Submit' type='submit' value='Submit' /></form>";
}
?>
However, when I run install.php, the resulting variables.txt file contains this:
Code: Select all
 = 'http://www.danedesigns.com';
 = 'great';
It shows that the text I want (which is wrapped in quotes, so should not be executing), is in fact executing before it is written to the page.
Reply With Quote
  #4 (permalink)  
Old Aug 31st, 2007, 19:36
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Fwrite to certain area on a page

could you not create a class called settings, like this:
PHP: Select all

new Settings {
static 
variables = array(
'siteurl' => 'default',
'password' => 'default'
);

then use do some thing like Settings::variables['siteurl'] = $variable;
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #5 (permalink)  
Old Aug 31st, 2007, 19:55
Reputable Member
Join Date: Jan 2004
Location: California
Age: 19
Posts: 232
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via AIM to tox0tes
Re: Fwrite to certain area on a page

I got the thing working almost. Now the problem is that when I use the include code:

PHP: Select all

<?php include "variables.txt"?>

It doesn't execute what is contained in the include, so it is simply displayed as plain text on the page.

I am afraid that I will have to put the <?php and ?> in the variables.txt file for it to execute, but that would make things much more complicated since all the content from variables.txt is generated from the fwrite...

Last edited by tox0tes; Aug 31st, 2007 at 19:57.
Reply With Quote
  #6 (permalink)  
Old Aug 31st, 2007, 20:01
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Fwrite to certain area on a page

this file will contain the password to the cms..
and you gave the extension ext
anyone can come along and view it and see the password
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #7 (permalink)  
Old Aug 31st, 2007, 20:01
Junior Member
Join Date: Jan 2007
Location: South Cambs, UK
Age: 18
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to afmanuk
Re: Fwrite to certain area on a page

Nah nah nah... You need to escape the $ by using backslashes, cause echo "$var"; will echo the contents of the $var variable, and because $siteurl and $password are not set, it writes nullspace to the file...
Should look like this...
PHP: Select all

$siteurl1 $_POST['siteurl'];
fwrite($fh"\$siteurl = '".$siteurl1."';\n");
$password1 $_POST['password'];
fwrite($fh"\$password = '".$password1."';\n"); 
Works similar to the \n
Reply With Quote
  #8 (permalink)  
Old Sep 1st, 2007, 10:35
Junior Member
Join Date: Jun 2007
Location: IRan
Age: 19
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to bahy Send a message via Yahoo to bahy
Re: Fwrite to certain area on a page

okay afmanuk !
i works too :
PHP: Select all

$siteurl1 $_POST['siteurl'];
fwrite($fh'$siteurl = \''.$siteurl1."';\n");
$password1 $_POST['password'];
fwrite($fh'$password = \''.$password1."';\n"); 
finaly u have to use " \ " !!
Reply With Quote
  #9 (permalink)  
Old Sep 1st, 2007, 20:29
Reputable Member
Join Date: Jan 2004
Location: California
Age: 19
Posts: 232
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via AIM to tox0tes
Re: Fwrite to certain area on a page

Quote:
this file will contain the password to the cms..
and you gave the extension ext
anyone can come along and view it and see the password
Yeah, that's a problem. For the time being, this include page has a randomly generated name so people can't just guess it. Also, they can't browse the contents of the admin folder, so technically, there shouldn't be a way to view the contents of this text file. Right?

As for the problem, I got it fixed by putting a $-variablename and then used string replace to take out the "-" before it is processed. This seemed to work. THanks for the help.
Reply With Quote
  #10 (permalink)  
Old Sep 1st, 2007, 22:44
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Fwrite to certain area on a page

Quote:
Originally Posted by danedesigns View Post
Yeah, that's a problem. For the time being, this include page has a randomly generated name so people can't just guess it. Also, they can't browse the contents of the admin folder, so technically, there shouldn't be a way to view the contents of this text file. Right?

As for the problem, I got it fixed by putting a $-variablename and then used string replace to take out the "-" before it is processed. This seemed to work. THanks for the help.
Wouldn't it be easier just to make it a php file?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Tags
php

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello from DC area imageworks Introduce Yourself 14 Feb 8th, 2008 08:43
Fwrite with new line break problem? meth8200 PHP Forum 2 Feb 4th, 2008 15:23
fopen, fwrite, fclose errors, really got me stuck! simbo1231 PHP Forum 10 Dec 8th, 2007 15:19
2+2 =? pic doesn't fit in defined area rubyfruit Web Page Design 9 Oct 18th, 2006 05:34
Page Area robukni JavaScript Forum 3 Feb 5th, 2006 17:17


All times are GMT. The time now is 02:14.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43