Log in

View Full Version : Trying to do something that I am not sure if can be done



CSF
06-03-2007, 04:56 AM
Alright I will start from the begging to try and make this make sense

I already use this script to make some CSS switches

Link (http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm)

Now how I set up my site is with a main page that's using this php code to reference a header and footer file.


<? include("file name"); ?>

What I would like to do is allow the user the ability to pick deferent footer and header files, does any one have any ideas on how this can be done?

One way I was thinking this can be done was through a script that allows the user to switch div sections.

I have tried modifying the css script but it could be I really have no JS experience at all.

Any help would be greatly appreciated.

djr33
06-03-2007, 09:59 AM
PHP is parsed before the page loads, so you can't dynamically change what the PHP did.

However, you can change this based on the user in a few ways:
1. You could load all of the possible divs and switch them on command
2. You could use ajax to load a div (though this means you don't need PHP and that you require ajax, which not all browsers support)
3. You could do this serverside, with a database and load the required page with PHP, as stored in the database as the user's choice.

One other possibility would be to just change the CSS for the whole page, if that happens to be all you need, in terms of "choosing skins".

CSF
06-03-2007, 05:04 PM
You could use ajax to load a div (though this means you don't need PHP and that you require ajax, which not all browsers support)
Ya from what I have heard I rather stay away for ajax for now.



You could do this serverside, with a database and load the required page with PHP, as stored in the database as the user's choice.

From the way this sounds the people would have to b registered on the site and then it will remeber the settings of that user name. I rather this be open to every one not just registered members.


You could load all of the possible divs and switch them on command
How I guess this would be done is bye some type of script that would let the user select which div they would want to use?


PHP is parsed before the page loads, so you can't dynamically change what the PHP did.
I figured if user selects a deferent php then couldn't the page reload with the new style and then through a cook save the settings but from reading your post it seams all the PHP is red first so once it is read there is no way to control it?

djr33
06-03-2007, 07:02 PM
There are, as you said, downsides to all the methods. However, you probably just have to pick one if you need this to work. It's not just an easy thing, sadly.


For the serverside option, you could instead use the IP to track, or a cookie (PHP can read cookies).

For loading divs, you would load all of them with PHP, probably set them to hidden, then change a single div at a time to visible, with the others still hidden. Or you could load into javascript as variables the other div's contents, then just change the content of the head/footer divs. It's up to you, and there are several options.


For using PHP, you would need to refresh the page.
You could use GET variables in the url to control it, though.
Use, to change it--
<a href="this.php?head=head1">

Then in the PHP, you can get this value and use it for the include:
<?php include($_GET['head'].'.txt'); ?>You could include some error checking if you'd like too.

That would take the value of the variable (in the case of the link above it would be head1) and include [that].txt for the header

However, this would only work once and wouldn't stay with the user on multiple reloads unless you were sure to keep that value in the url. You could use sessions or cookies (or a database with the IP) to track this, though, if needed.

mburt
06-03-2007, 07:09 PM
This is a major security leak:

this.php?head=../*.txt
Use predifined links that can be only accessed by the PHP script, example:

if ($_GET["head"] == "value 1..")

CSF
06-04-2007, 03:38 AM
I think the route I am going to go is using php to control div and then use a php cookie to keep track of it so any information / links you can give me about doing this will greatly be appreciated.

CSF
06-04-2007, 04:39 AM
Sorry if this double post is a problem I looked in the rules and dint see any thing and want to make sure this is seen.

While searching the web I fount some code and tided to modify it see if I can get it to do what I need



<?php
if(isset($_GET["header"])) $header = $_GET["header"];
else $header = "Layout/header1";

switch $header;
{
case "h2" Layout/header2;
case "h3" Layout/header3;
case "h4" Layout/header4;
case "h5" Layout/header5;
default Layout/header1
}
?>


I seam to be getting an eror message when I try to execute it, does any one see what may be wrong?

Second I know this may sound stupid but how exactly would I select which case to use?

djr33
06-04-2007, 06:17 AM
switch ($header) {
case 'h1':
$h = "Layout/header1";
break;
case 'h2':
$h = "Layout/header2";
break;
case 'h3':
$h = "Layout/header3";
break;
default:
$h = "Layout/header_d";
break;
}

CSF
06-05-2007, 02:50 AM
Alright after experimenting with the php it dosn't like it will be posible to get the desired results.

So by any chance does any one have a link to a java script that switches div sections?