www.webdeveloper.com
Results 1 to 11 of 11

Thread: Can I use PHP rather than an Iframe?

  1. #1
    Join Date
    Sep 2006
    Posts
    213

    Can I use PHP rather than an Iframe?

    I was wondering if I could use PHP to embed my CGI Email form in my index page. My host requires that I put my CGI script in a special folder (CGI wrapper) so including it on the index page is not possible unless I embed it somehow. I really donít want to use an iframe. Can I accomplish this with PHP? Could someone provide an example?

  2. #2
    Join Date
    Dec 2006
    Posts
    32
    Yes. Just use a PHP include. Let's say I wanted to include form.html on index.php...

    Code:
    <?php include("form.html"); ?>
    Simple as that.

  3. #3
    Join Date
    Sep 2006
    Posts
    213
    So it's size is defined by the element it's embedded in? Let's say:

    <div style="width:300px; height:300px;">
    <?php include("form.html"); ?>
    </div>

    And there's no extra coding for the page to be embedded(In this example the page called "form.html")?

    I ended up using an ajax and it works fine but if my host will allow me to do this instead I think it'd be a better way to go (no JS). Thanks for your help PHPSHIFT2.

  4. #4
    Join Date
    Sep 2006
    Posts
    213
    I contacted my host and they said it's supported, but I'm still unable to get it to work. I read this somewhere: "The way PHP handles the ./ and ../ is totally counter intuitive." But they didn't really elaborate.

    If my parent html file (index.html) is in the root and I want to access a file that's in a folder in the root, normally I'd write the path like this: "folder/form.html". Is the path different in PHP?
    Last edited by bustya; 12-27-2006 at 07:50 AM.

  5. #5
    Join Date
    Jun 2006
    Posts
    472
    I would use
    PHP Code:
    <?PHP include('./folder/form.html');?>

  6. #6
    Join Date
    Dec 2006
    Posts
    32
    Well, "./" stays in the same directory while "../" goes up one directory. It's pretty simple. Let's say you were in "yoursite.com/dir/subdir" and you wanted to include the file "yoursite.com/dir/difdir/form.html". You'd just do this:
    PHP Code:
    <div style="width: 300; height: 300; overflow: auto; ">
    <?php include("../difir/form.html"); ?>
    </div>

  7. #7
    Join Date
    Sep 2006
    Posts
    213
    Thanks again PHPSHIFT2, but it appears my troubles are with my host and not my code. I tried this a million different ways (PHP, ASP, ISS) and it still isn't working. I notified my host and they're dumbfounded. I think the trouble is that PHP support hasn't been activated on my account, but I've looked all through my CPanel and can't find where I need to activate it. So I'm hoping the support folks can steer me in the right direction. To try to weed out the problem I uploaded two test files to the same directory and used the path "./red.html" and it's not working.

    Question: ./ = this directory and ../ = up one directory so ./folder/file.html will look in the current directory for a folder and then inside that one for the file, right?

    That's the path I'll need to take if support can figure out why my account is malfunctioning.
    Last edited by bustya; 01-15-2007 at 11:59 AM.

  8. #8
    Join Date
    Jun 2006
    Posts
    472
    try renaming it to testphp.php not html

  9. #9
    Join Date
    Dec 2006
    Posts
    32
    Quote Originally Posted by aussie girl
    try renaming it to testphp.php not html
    Precisely. Name it testphp.php. Simple solution.

  10. #10
    Join Date
    Dec 2006
    Location
    Escazķ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    From your original question, my understanding is that the page that you are trying to include is a CGI script, then including it via "include()" will not really work because the only processing that will be applied to it will be PHP and not whatever CGI Handler has been defined on the web server. The reason is that PHP does a local file system read on the file and then applies PHP rules to whatever it finds in there. If it's non-PHP, it will just output as-is whatever it finds.

    You may not like it, but ultimately, you may have to resort to a <frame> or <iframe> to get the CGI script to run as it should and display the results in a semi-controlled fashion.

    There could be another way, which would be to use the so-called "Apache-specific Functions" (see: http://www.php.net/manual/en/ref.apache.php), but I've never done it so I'm not going down that road. But perhaps someone else has experience with it...

  11. #11
    Join Date
    Sep 2006
    Posts
    213
    Quote Originally Posted by aussie girl
    try renaming it to testphp.php not html

    Yep that was the issue, this was my first experience with PHP and I didn't realize. Thanks everyone.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles