Jul 24, 2008

How To Do This

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

How To Do This

mahirharoon
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
CODE
<?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
CODE
<?php

$variable = $_GET['id'];

switch($variable) {

default: include('home.php'); break;
case "guestbook": include('guestbook.php'); break;
case "forum": include('forum.php'); break;


}

?>

 

 

 


Reply

sonesay
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.


QUOTE
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.

Reply

shadowx
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:

CODE
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

 

 

 


Reply

mahirharoon
QUOTE(sonesay @ Dec 7 2007, 12:06 AM) *
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

Reply

gogoily
You should use function "file_exists('filepath')" if you wanna check whether the PHP file created or not

Reply

mahirharoon
i wrote the code for writing into the switch
CODE
<?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";
};
   }
?>

Reply

mahirharoon
sorry for double post
i also wrote the code for opening it and creating it if not extisting
CODE
<?php
$handle = fopen("index.php", "a+");
?>

EDIT:the main problem is it will be inserted after define tag (<?php?>)

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics
Looking for How, To, Do, This

Searching Video's for How, To, Do, This
advertisement



How To Do This



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE