Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: PHP Include, Then Change File By Link

  1. #1
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default PHP Include, Then Change File By Link

    I know this is possible, but i can't find the tiny bit of coding.

    If i have 'Page1.html' Included Into My Webpage Using PHP Include

    How Do I make a link, so i can put Page2.Html there instead just like and iframe

    I thinks its PHP.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    It'd have to reload the page or use ajax. Heres for it to reload the page:
    PHP Code:
    <?php
    switch($_GET['changePage']) { //switch is just like a bunch of if()s
        
    default: //default case
        
    case 'default'//default case
        
    include('page1.html'); //include page.html
        
    break; //break, witch means stop
        
    case 'page2'// page2, if changePage has the value of page2
        
    include('page2.html'); //include page2.html
        
    break; //stop it
    //end the switch
    ?>
    The above is assuming you have the basic knowledge of switch()
    Now to change it:
    HTML Code:
    <a href="page.php?changePage=page2">Page2</a>
    Now, your wondering why I just don't do this:
    PHP Code:
    include($_GET['changePage']); 
    Its unsecure, for example if that page is protected by htaccess files, it won't protect the include.
    If you don't understand the first script I gave you, please lemme know.
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    That last one was it, i remember when i saw it.

    but after reading that, i'll use the first script.

    But my site is an online radio so.

    So the page cant refresh or my radi owill stop.

    is there a way of doing it silently

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ajax, I suggest taking a look at this:
    http://www.dynamicdrive.com/forums/s...highlight=ajax
    There are so many ways to do it without PHP, but then if the browser doesn't support javascript, the code will fail.
    Jeremy | jfein.net

  5. The Following User Says Thank You to Nile For This Useful Post:

    Swaydo (08-11-2008)

  6. #5
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Ok i will have a look at that.

    Its not Majorly important, it actually to change the background color.

    i cnt do it via style switcher as i use that to change skin color.

    So Thanks.

  7. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    So then why not use javascript:
    HTML Code:
    <a href="javascript:void(0);" onClick="document.body.style.background='lightgreen';">Light Green</a>
    Jeremy | jfein.net

  8. The Following User Says Thank You to Nile For This Useful Post:

    Swaydo (08-11-2008)

  9. #7
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default :o

    Becuase i didnt know you could.

    Thanks alot!

    Im gonna use the ajax script for content now.

    Tysm

  10. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Lol, well there you go, glad to help.
    Jeremy | jfein.net

  11. #9
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default



    And can i use them links to set background images?

  12. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Indeed you can:
    HTML Code:
    <a href="javascript:void(0);" onClick="document.body.style.background='url(http://www.dynamicdrive.com/forums/designfiles/logo.gif)';">BG</a>
    BTW:
    You can use buttons too:
    HTML Code:
    <button onClick="document.body.style.background='url(http://www.dynamicdrive.com/forums/designfiles/logo.gif)';">BG</button>
    I hope this helps,
    Nile
    Jeremy | jfein.net

  13. The Following User Says Thank You to Nile For This Useful Post:

    Swaydo (08-11-2008)

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
  •