how to structure this...???

Discussion in 'PHP' started by wrekoniz3, Sep 4, 2010.

  1. #1
    so i wanna be able to have a condition like this....

    if device == Test

    then include Test-home.php


    if device == test2

    then include test2-home.php




    Thats an example. i want a way to load a page inside a URL so i can have different versions of the page loading on the same url. but i dont wanna have to worry about escaping 800 lines. how can i pull it off?
     
    wrekoniz3, Sep 4, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    If I understood you correctly, you can do it like this:

    
    <?php
    for($i=1; $i<10; $i++){
        if($device == "test".$i){
          include "test".$i."-home.php";
        }
    }
    ?>
    
    PHP:
     
    s_ruben, Sep 4, 2010 IP
  3. wrekoniz3

    wrekoniz3 Well-Known Member

    Messages:
    2,232
    Likes Received:
    100
    Best Answers:
    0
    Trophy Points:
    190
    #3
    oooo thats interesting. im talking more on the lines of a device i put test 1 ....2 in for the example.


    its gonna be more like if device == iphone

    then

    include iphone-home.php

    but i dont want to have to escape out the entire iphone-home.php page. because im going to have an entire pages content.. and im gonna have an iphone- version of my entire site. and a blackberry- but like i want to keep all the same pages visually thats why i want to use this system. internally this is whats gonna happen but user end they go to home.php and if they are on a particular device then that device-home.php is loaded but it still shows home.php as the url. same with any page on the site. and i dont want to have to escape out EVERY PAGE, because i have a full socal networking site im recoding into this. options to that?
     
    wrekoniz3, Sep 4, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    You just do something like this:

    
    <?php 
    if ( $thisDevice == 'something1' ) {
    // include something
    }elseif ( $thisDevice == 'something2' ) {
    // include something else
    }elseif ( $thisDevice == 'something3' ) {
    // include something else
    }
    ?>
    
    PHP:
    ..and so on... that's just my way, there's probable an easier solution.
     
    MyVodaFone, Sep 4, 2010 IP
  5. Wolf Security

    Wolf Security Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    switch ($device)
    {
    	case "device #1":
    		include("home-1.php");
    		break;
    	case "device #2":
    		include("home-2.php");
    		break;
    	default:
    		include("home-unknown.php");
    }
    PHP:
     
    Wolf Security, Sep 4, 2010 IP
  6. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #6
    HuggyEssex, Sep 4, 2010 IP
  7. TheWiseGuy

    TheWiseGuy Member

    Messages:
    113
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #7
    What do you mean by escaping?
    if you want to include a page whose name is based on a string variable you can do it this way:
    <?php 
    $st = "-home.php";
    $devicename = $yourvar;
    $st = $yourvar."-home.php";
    include $st;
    }
    ?>
    PHP:
     
    TheWiseGuy, Sep 4, 2010 IP
  8. wrekoniz3

    wrekoniz3 Well-Known Member

    Messages:
    2,232
    Likes Received:
    100
    Best Answers:
    0
    Trophy Points:
    190
    #8
    sorry for the late reply. Yeah i did it similar to that @thewiseguy i did somethign like this

    $pageid = index.php <--- on the physical page...


    then i used a system which groups user agents so if a useragent has the term iphone in it, then device == iphone

    so then i created copies of every page and set a system to redirect if mobile == 1

    and it redirects to $device - .$pageid. so iphone-index.php

    etc etc.

    thats a general idea of how i pulled it off. Thanks for your help though? any of you have skype?
     
    wrekoniz3, Nov 8, 2010 IP
  9. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I will go with the switch case because it is faster than else if.
     
    xpertdev, Nov 10, 2010 IP