Results 1 to 9 of 9

Thread: Trying to do something that I am not sure if can be done

  1. #1
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to do something that I am not sure if can be done

    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

    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.

    Code:
    <? 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.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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".
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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 Code:
    <?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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    This is a major security leak:
    Code:
    this.php?head=../*.txt
    Use predifined links that can be only accessed by the PHP script, example:
    Code:
    if ($_GET["head"] == "value 1..")
    - Mike

  6. #6
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  7. #7
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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 Code:
    <?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?

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
    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;

    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

Bookmarks

Posting Permissions

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