Dynamically Created FIles Not Running PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
The14thGOD
Forum Newbie
Posts: 1
Joined: Thu Aug 06, 2009 2:22 pm

Dynamically Created FIles Not Running PHP

Post by The14thGOD »

I used PHP to create new pages based off a user input and pre-exisiting "templates" I made. The PHP code runs and creates the files just fine but when I go to view them everything is there except the php includes. I downloaded the files off the FTP and they are exact copies (besides 2 lines of code that I needed to change based off the user input). So basically all the HTML renders but the PHP is ignored (and it's not being displayed to the browser). Are there permissions or settings or is there some code I'm missing to make the PHP run off of these created pages?

Here's the code that makes the pages:

Code: Select all

<?php
    import_request_variables('pg');
    if($send=='send'){      
        include('edited out');
        //Insert data into databases
        $newpage = "$page_link".".php";
        $query = "edited out query";
        mysql_query($query);
        include('includes/random_gen.php');
        $pageid = get_rand_id(10);
        $query2 = "edited out query";
        mysql_query($query2);       
        //create new files
            //create new pages, front end page, back end page
            switch($layout){
                case 1:
                    $filename = '../templates/three_cols.php';
                    $filename2 = 'templates/three_cols.php';
                    break;
                //etc etc truncated to make easier to read
            }
            //open files for reading
            $fh = fopen ($filename, "r") or die ("couldn't open file");
            $fh2 = fopen ($filename2, "r") or die ("couldn't open file");
            //get data from files
            $data = fread($fh,filesize($filename));
            $data2 = fread($fh2,filesize($filename2));
            //close files
            fclose($fh);
            fclose($fh2);
            //new files
            $fh = fopen("../$newpage","w") or die ("couldn't make file");
            $fh2 = fopen("$newpage","w") or die ("couldn't make file2");
            //replace content in the data
            $data = str_replace('0000000000',"$pageid",$data);
            $data2 = str_replace('0000000000',"$pageid",$data2);
            //Proper navigation heading?
            switch($parent_page){
                case 1: //home
                    $data = str_replace('<body>','<body id="page1">',$data);
                    $data2 = str_replace('<body>','<body id="page1">',$data2);
                    break;
                //etc etc...truncated to make it easier to read
            }
            //write the data into the files
            fwrite($fh,$data);
            fwrite($fh2,$data2);
            //close files
            fclose($fh);
            fclose($fh2);           
            //set permissions
            chmod("../$newpage",0644);
            chmod("$newpage",0644);
        //end file creation
        header("Location: $newpage");
        exit(0);
    }
?>
I tried setting permissions to 0755 as well but no luck there.

Any help is greatly appreciated, thanks,
Justin
marty pain
Forum Contributor
Posts: 105
Joined: Thu Jun 11, 2009 5:32 am
Location: Essex

Re: Dynamically Created FIles Not Running PHP

Post by marty pain »

just a quick thought, change include to require and see if the script still runs. It might throw up a problem with actually finding the included files.
Post Reply