Jump to content
xisto Community
Sign in to follow this  
mahirharoon

How To Do This

Recommended Posts

i don't think i wrote a good topic title
how to do this:
on a page with a text box and a button
when the user writes what page he wants into the
textbox
and clicks the button
it looks for the file and create it with a php extension
and adds it to the page switcher
and case is added by putting the same query
whthout the extension
example
if the code of the page switcher is

<?php $variable = $_GET['id'];switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;}?>
the user writes forum.php
then the code will become
<?php $variable = $_GET['id'];switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;case "forum": include('forum.php'); break;}?>

Share this post


Link to post
Share on other sites

Im sorry but your not very clear please rewrite it so we can understand better what you are trying to do exactly. I got the part about you wanting to have an input text box and button for submitting.


it looks for the file and create it with a php extension

I dont know what you want to do here exactly. Create a whole new php file? or just add the entry to your case switch.

Share this post


Link to post
Share on other sites

Well to create the php file is easy enough, just google the
FREAD, FOPEN and FWRITE functions and that will tell you how to search for and create a file

As for editing that php file... well the best way to do it would be to use FREAD to read the contents of the page switcher into a variable, and then search that variable fr the end of the switch function EG:

switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;case "forum": include('forum.php'[color="#FF0000"][i][u][b]); break;}[/b][/u][/i][/color]

So your search critera would be "); break;}" you can use "in_str" or a similar string search function to search that new variable for this criteria, this would give you the cursor position of the last bracket "}" in that switch function. From there you could go back a space then add a newline to the file and enter the new line EG "case "profile": include('profile.php'); break;"

its a bit confusing i know but it does make sense to me

Share this post


Link to post
Share on other sites

Im sorry but your not very clear please rewrite it so we can understand better what you are trying to do exactly. I got the part about you wanting to have an input text box and button for submitting.I dont know what you want to do here exactly. Create a whole new php file? or just add the entry to your case switch.

it looks for the php file and will create it if it is not in the directory specified
and adds the entry to case switch

Share this post


Link to post
Share on other sites

i wrote the code for writing into the switch

<?php$filename = 'index.php';if (is_writable($filename)) {	echo 'The file is writable';} else {	echo 'The file is not writable';}if (is_writable($filename)) {$filename = 'index.php';$somecontent = "the code.....";// Let's make sure the file exists and is writable first.if (is_writable($filename)) {	if (!$handle = fopen($filename, 'a')) {		 echo "Cannot open file ($filename)";		 exit;	}	// Write $somecontent to our opened file.	if (fwrite($handle, $somecontent) === FALSE) {		echo "Cannot write to file ($filename)";		exit;	}	echo "\n Success, wrote ($somecontent) to file ($filename)";	fclose($handle);} else {	echo "\n The file $filename is not writable";};   }?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.