Newbie at this PHP stuff...
July 13, 2009 9:46 PM   Subscribe

PHP / Javascript question - Lightbox (and Greybox, for that matter) doesn't seem to want to play nicely with my "include" function.

I'm trying to integrate the LightBox app into my new website.

The site's basic structure is an index.php page that uses the "include" function to call up each of the subsections. Like so. The page I want lightbox on is the "art.html" page, which shows up as "http://www.phirephoenix.com/testing/index.php?page=art". It's stored in "http://www.phirephoenix.com/testing/content/art.html".

I've replaced the original "art.html" page with the default file that comes with the Lightbox download, to make sure I didn't screw up any filenames while I was porting it over. As you can see, the effect works fine in the "art.html" page as a standalone, but not when it's viewed as part of hte "index.php" file.

So my only conclusion is that it must be something in the php that's causing it to go haywire, as I've included the headers (referring to the javascript) in both the "art" page and the "index" page as a precaution.

Here's the php I was using -

<?php if (isset($_GET['page'])) { include("content/$_GET[page].html"); }  else include ("content/home.html"); ?>

It seems inconceivable that a simpe 'include' function could cause this problem, but I can't think of anything else.

I've tested the site with Greybox as well, with the same problem. Hope me!

posted by Phire to Computers & Internet (10 answers total)
 
If you look at the source, you have all the html and head tags inside of your included script..so they repeat twice when you include it in index.php. You need to only have content in the include and all the headers need to be on your main index.php file.
posted by Sonic_Molson at 10:02 PM on July 13, 2009


Well, it looks to me that problems might arise from the inclusion of the additional head and body tags and html docstring from art.html. You should only include the relevant lightbox javascript files in your header. Basically strip out anything that isn't links to the lightbox css and javascript in your art.hml file, and then move the include statements to the header of index.php. On preview, Sonic_Molson's beat me to it.
posted by Mister Cheese at 10:06 PM on July 13, 2009


Response by poster: Should the javascript rels be in the index.php header, or the art.html header?
posted by Phire at 10:07 PM on July 13, 2009


Ugh, actually, ignore what I just said. Sonic_Molson's got it right.
posted by Mister Cheese at 10:09 PM on July 13, 2009


Response by poster: Wait, sorry. I think I misunderstood the first time.

Basically:

index.php should have the html, body, and head tags, as well as the links to the javascript

art.html should have the html, body and head tags and the main content.

Do I have that right?
posted by Phire at 10:11 PM on July 13, 2009


Best answer: index.php should have html, body, and head tags, as well as the links to the javascript.

art.html should have only what you want to go in between the body tags of index.php

The php include statement should be in between the body tags of index.php.

The php's include statement inserts whatever is in the file that's specified. Since index.php's already got html, head, and body tags, their inclusion from art.html is probably messing things up.
posted by Mister Cheese at 10:20 PM on July 13, 2009


Best answer: Ok first, Don't do this:
include("content/$_GET[page].html")

See this

Second all an include does is take the text you have in the included file and include it at that point, there's no magic that strips out extra html and body tags. All your home.html file should have in it is:

<b>July 13, 2009</b><br />
The skeletal structure of the site is finally up! I'm thinking eventually I'll want the front page/updates section of the site to be run via Word Press, but for now it's good enough. Art + Writing + Contact are up, Links and Comic are still under construction. I'm hugely busy this week (I have to finish up a sponsorship package for my debating club and write an essay for Sociology) but I hope to have that done next week. Then onto my portfolio site. Yay for getting off my ass! :)

Art Should NOT have head tags or html tags or body tags, only the stuff that goes between your body tags. Look at your source in your browser and you'll see what's happening.
posted by bitdamaged at 10:25 PM on July 13, 2009


Response by poster: Thanks, bitdamaged. I'd heard about the security flaw but hadn't had a chance to look into how to fix it yet.

I understand that I should be stripping out the extraneous head/html/body tags in the body sections, but here's the odd thing.

Linking the javascript files in the index.php file was part of the problem (the other part of the problem was that my site had become disorganized and I was linking the wrong file, despite my attempts to be careful). So linking the javascript files in the art.html file, like this page, now works (click on "updates" to see what I mean).

How can I link the files in the head while avoiding redundancy?
posted by Phire at 10:30 PM on July 13, 2009


Best answer: A quick look suggests a couple of things:
  • If you look at the source of http://www.phirephoenix.com/testing/?page=art, you'll notice that inside the <body> section of the main page you've got a whole webpage, with its own associated <html>, <head>, and <body> declarations. This is not valid HTML, so all bets are off on how it's going to behave.
  • The JS includes (e.g. <script src="js/prototype.js" type="text/javascript">) in the art page are relative links. I'd suspect you've got them installed under /testing/content/ (e.g. /testing/content/js/prototype.js) but since the location of the main page is /testing/, it's looking for them under /testing/js (e.g. /testing/js/prototype.js).
Either way, it's not a PHP problem - it's a HTML &/or path problem. Strip the art page down to everything between the <body> & </body> tags, move the script includes to the header of your main index.html page*, and see if that works.

(* This is not ideal - the scripts will get loaded regardless of whether the art page is being viewed or not - but will do for testing, and it's not such a big deal in practice anyway...)

On preview: what everybody else has said.
posted by Pinback at 10:38 PM on July 13, 2009


Response by poster: Thanks everyone! A combo of suggestions and error checking and it now works. For future reference, Mister Cheese summed up my current set-up. I've taken off the test sites so the links won't work, but the finished site is in my profile for anyone who's interested.
posted by Phire at 5:38 AM on July 14, 2009


« Older What did he do that made you cheat?   |   How to go from a little girl with a guitar to a... Newer »
This thread is closed to new comments.