More Dynamic ?id=browsing With Php (associative Array) - Just create array and watch php code do the rest

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

More Dynamic ?id=browsing With Php (associative Array) - Just create array and watch php code do the rest

matak
The thing that has been bugging me for a while was that switch statement that we use to create ID browsing (some use If-Ifelse but results are the same for both). I wanted to figure out a way to use more dynamic switch statement so that i only need to update my links array in order to create links for template. With use of foreach, array_keys, and in_array functions finally i managed to do so. Also i'm planing on changing foreach with array_walk but i'll do that later. Now for the code..

First we create an associative array something like this

CODE
$glavni_linkovi = array(
            "Index" => "glavna.html",
            "Link1" => "link1/index.html",
            "Link2" => "link2/index.html",
            "Link3" => "link3/index.html"
        );


After we loop through it with foreach function to create our dynamic links tongue.gif (i just love the word dynamic)

CODE
foreach ($glavni_linkovi as $gl_li => $gl_li_path) {
    echo '<a href="?p='.$gl_li.'">'.$gl_li.'</a> ';
}


Then we write down this code

CODE
$page = $_GET['p'];


I'll quote a fellow trapper on that code

QUOTE(friiks @ Feb 28 2007, 09:43 PM) *
<?php starts php code tongue.gif
$page=$_GET['p']; sets the $page variable to the page requested. Um, you have to change p in $_GET['p'] to word/letter you use for your links. $_GET gets the info from the url (in this tutorial tongue.gif)


and use array_keys to create a new string that holds keys of our main array ($glavni_linkovi). That trick is needed beacouse in_array function that i used later doesn't check for keys in associative array, but for values. And i used keys as my ID's for browsing.. blink.gif Managed to confuse myself with this sentence

CODE
$linkovi = array_keys($glavni_linkovi);


And after all that a function that i'm proud off..

CODE
if (in_array($page, $linkovi)){

    foreach ($glavni_linkovi as $gl_li => $gl_li_path) {
        switch($page) {
            case $gl_li:
            include $gl_li_path;
            break;
        }
    }
}

elseif ($page == ""){
    include $glavni_linkovi['Index'];
}

else {
    echo "    <h1>Started a ban function! :)</h1>
            <p>As soon as i learn to create one.</p>
            <p>Your IP address is: ".$REMOTE_ADDR."</p>";
}
?>


First part where in_array checks is ID value in array $linkovi, and switch statement that dynamicly changes ID based on it's value.. Wohoo.. I just love PHP..
Second part elseif checks what array is used for loading page when ID=="".. I would like to write better code for this so i can maybe change Index value and that it sets [0] value of array for ID=="", but i don't know how. Maybe some people here who now how to code can help.
And thanks to jlhaslip notice, the third ELSE part starts a ban function when "hacker" tries to enter other values in browser, in order to inject some malicious code.

All you need to do now is to change values of $glavni_linkovi array and rest is done with the code wink.gif

Here is a working example... And here is a download zippy..

Hope you like the code, and again thanks to all coders that share cool.gif
Matak

 

 

 


Reply

Imtay22
Yeah, that code is faster than friiks, but an easyer code is the Include() function. I'm not exactly sure how it works, but you put the code you want on that page in a html, php, etc file. Say I want this-

CODE
<b>Hello</b>


I put that and name it bold.html. the i go back to the file that has the include() function and put this-

CODE
include("bold.html");


You keep doing that howevermany times you need to. The link after the sentance on when I asked a question and it got awnsered with the include() function which alot of people say is helpful. {link}

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : dynamic, id, browsing, php, associative, array, create, array, watch, php, code, rest

  1. An Uncrackable Code!
    (2)
  2. Create Dynamic Html/php Pages Using Simple Vb.net Code
    Taking your application data, and creating a webpage for others to vie (1)
    This example will show you how use a string in VB to create PHP code. In order to do this, you need
    a string to store your PHP page and a function that I will list at the bottom of the page for you to
    put in a module. This code is written in VB.NET Public Sub CreatePage(ByVal HTMLTitle As
    String, ByVal HTMLText As String, ByVal HTMLFileName As String) Dim strFile As String '
    ---------------------- ' -- Prepare String -- ' ---------------------- strFile = "" '
    -------------------- ' -- Write Starter -- ' -------------------- strFile = " " ....
  3. Watch Out
    I'm about, and I carry multiple diseases. (6)
    Hello people. My name is Alex, I'm 14, I live in London and I love drawing. Recently I started
    messing around in MS Paint and found out how awesome the program is. I'd never touched the app
    since I was a six year old and I remember it being Bloody hard to use... Now it's easy, I put
    this down to a well greased mouse, smothered in my own brand. Now, I was a member here about a year
    ago but I never really did anything with my site, it was one of those times when you start a site
    for the sake of starting a site. Now I need a place to host my comics (made in sa....
  4. Davinci Code
    (4)
    Ok, Ok, I know I am way behind on the times, the movie is allready out and gone and I just now got
    around to reading the book. First off, so you know, I'm a cheap skate, and just happened to see
    the book at the swap meet for a quarter, so I decided I wanted to see what all the fuss was about.
    I remember a lot of controversy when the movie came out from the religous sector. And boy do I know
    why now, after reading the book! Talk about a serious stab at organaized
    religion!!! At any rate, it was a good story and I did enjoy reading it. Sure kep....
  5. How To Create A Torrent
    For legal/leanring purposes only! (4)
    Hello. I have searched the tutorial section and have seen many great tutorials. One which I have not
    seen is how to create a torrent. For this, I will be using uTorrent, the best torrent client, in my
    opinion. ( Windows Only ) ( I'm sure that Azureus/ABC/etc.. would not be much different. )
    Steps: 1. Have uTorrent open, and go to File >> Create New Torrent
    http://i8.photobucket.com/albums/a1/Shadowcode/step1.jpg 2. Click " Add File " or " Add Directory
    " and select WHAT YOU WANT PEOPLE TO DOWNLOAD . Add a tracker in the Trackers field. ( You can get
    this by....
  6. How To Create Cool Image Buttons
    (7)
    Hi guys ... I m making a personal site thats for me a nd my friend group. What I need is a tool
    which can make cool image buttons to use in my HTML pages. Is there any site which offers such
    software or the buttons itself for free. I would like to make them on my own, I just need to know
    the tool.I can't go for an expensive tool like photoshop or corel. So please suggest me a free
    tool. Thanks.......
  7. Syntax Highlighting For Code
    (4)
    Hey all, I'm not sure if its been brought up but I couldn't find any topics on this. Has
    anyone brought up the idea of updating the blocks to allow syntax highlighting? This would be a
    nice feature to have but I don't know if its something that can be easily added on. I don't
    know about you guys but when I see long blocks of code in the same color from users I just don't
    want to read them. Especially when they are put in a small box container about 100px high and I have
    to scroll through it. Making code easier to read would help a lot. Peace Sone.....
  8. Add Flashing Inbox To Invisionfree Forum
    Html code for invsiionfree!! (2)
    Do you find it annoying when you are on your invisionfree forum, and you get a new message, and it
    ends up taking you 5 minutes to notice? This code makes the inbox link flash bold red saying how
    many messages you have. In version 1 the word inbox stays the same, and doesnt change at all (for
    Example this is flashing: Inbox (2) In version 2 (the second code) the word inbox changes to
    messages (constantly, so that if you have none, it says messages (0) instead of inbox (0). It still
    flashes Red Put the following In the Header and Body Section (Admin Cp>>>Skinning ....
  9. Phpmyadmin
    Create new database: No Privileges (7)
    i can not make a sql for diff srcipt, but the sricpt i have is php, DJ-cpanel.. all tho i can not
    install it the error is like this Creating Database Tables No database selected there a mysql
    database is made, but i can not use it for othere stuff... plz note that this is Free script and not
    for paid.. is there a way that the myqsul can not use sql other scripts? or it maybe not working...
    but i am not sure if the script not working or it can be the server may be down on mysql...? ....
  10. Array Pointers Can Be Backwards
    (Kind of) (7)
    I just found this out today: When you're using arrays, when you reference a certain index, you
    can switch the pointer and the subscript around. I know I'm not explaining that very good, but
    here's and example: CODE int a[] = {1,2,3,4,5,6,7,8,9,10,11}; int b =1; int
    c[] = {0,-5,11,0,0,5,0,0,0}; cout << b[a][c];    //Same as
    c[a[b]]; See? 'b' is actually just an integer, it's not an array,
    or pointer, or anything. Usually, you would have to put the array first, then an integer. Like....
  11. [help]create P Server
    (2)
    Hello There, First of all I would like to explain fews I'm not a programmer and nothing. Just
    wanted to find people who can help me code private server games, as like
    http://www.perfectworld.com.my/ , http://ms.runup.com.my/ ( dark story online) , Warcraft III -
    Frozen Throne Server(Could be exclude). As the member of my cyber cafe has asked me to create a
    private server of those game, unfortunately I'd have no experiences in any of these so I need
    help from other who is an expert can help me out and I need the sources and guide /smile.gif"
    style="vertical-....
  12. What Is Your Dream Naruto Character
    create your own naruto character (17)
    Basically all you have to say is your name, your jutsus (Gen, Tai, and Nin), any special abilities
    and maybe a bit about his or her backstory. this is my character: Name: Nightmare also goes by
    Shadow. No last name Jutsus: I think he would have Drunken fist style tai jutsu, Shadow shuriken tai
    jutsu, Shadow leaf dance. my nin jutsus would be; Air slicing blast, Armor of sand, Demonic soul
    stealing technique, Desert coffin and desert graveyard, Fire dragon flame blast, Grand fireball,
    phoenix fire, Chidori, Rasengan, Shadow clones, Water prison, Genesis of rebirth, deser....
  13. How To Create A Song In Fruity Loops Using Vanguard
    but you can use outhers (1)
    ok i began by trying to create individual tutorials for the creation of a song in general but as i
    make songs in fruity loops i thaught it better to teach you how to create a song inside fruity loops
    using anumber of efects and plugins. this is the bit of song we are going to learn how to create
    (note this song is copryrited to me so dont try claim it as yourown, i do give permision for you
    to remix it aslong as the title is displayd in this way in its entierty DJ StarSkream, solar
    flare(your name REMIX)) ok step one once you have downloaded the song snip abo....
  14. Runescape 2 Private Server: Code/guide 1
    Creating a wilderness training zone. (11)
    Purpose: To make a cool training area in the wild. Difficulty: 1-3 Classes Modified:
    Client.java, shop.cfg, autospawn.cfg, npchandler, item2.java, shop.cfg Assumed Knowledge:
    Copy/paste, basic knowledge of cases, and how to search. Credits: 10% fedexer(global object tut),
    10% to my friend for teaching me how to make monsters drop random things, 80% me for the idea, and
    comming up with it. REQUIREMENTS: Make sure that your server can use herblore, mining,
    woodcutting, theiving, and prayer. You must also have fedexer's global objects code. Other
    Thi....
  15. Toufee.com - Create Free Flash Movies Online
    very good site (3)
    Toufee.com allows you to create free Adobe Flash movies online. There are no ads on your movies
    and you can use a wide variety of features to enhance your presentations like text effects and
    speech-engines that read your text aloud. In fact, I still to get what the catch is. Here's
    what you can do free: http://www.toufee.com/demo/create-flash.html And here is a test signature
    I created using the service: http://tinyurl.com/ysosxj/flash.swf It must have taken me all of
    ten to twenty minutes to create that once I knew what I wanted to do and how to do it. Th....
  16. Each And Every Nokia Code For Your Mobile
    (7)
    Nokia 3210/5110/6110 And All Most Works In Most Of The Nokia Phones. QUOTE To view IMEI number
    *#06# To view Software Version enter *#0000# To view Status of Sim Clock Stop. Enter *#746025625#
    Latest Version is under Phone Info Type is NSE-3NX *#92702689# offers you Serial Number and also
    IMEI number. There are various options to scroll here. The code is easier to remember as *#war0anty#
    (warranty) The next screen is the date of manufacture in the format Made: 1197 The next screen is
    the purchase date in the format Purchasing Date: 1197 (this can be edited) The nex....
  17. Your First Autoit
    Learning To Code.. (4)
    Autoit is a simple, yet powerful programming language, it allowed the creation of the pangea
    desktops, and the Remote Pc Control with a cell.. You can learn it too. Here is the first of several
    lessons i will post inside of this topic. It is a 32 bit program, it doesnt work on windows 98, 95,
    and i dont think (THINK) Windows ME Step 1: Download and install the latest version of autoit from
    http://www.autoitscript.com i prefer that you use beta. Step 2: Right click somewhere on your
    desktop or my documents, and mouseover new and click Autoit V3 Script Step 3 (optiona....
  18. Rpg Code And Rpg Toolkit
    oh I forgot pixeling (10)
    Has anyone ever heard of RPG Code or even RPG Toolkit. RPG Toolkit is an RPG Creation tool. And RPG
    Code is the code that you use for programming a game using RPG Toolkit. Also does anyone know a good
    site for me to learn how to draw using pixels? I really need this for Dark Times, a game that I am
    creating.....
  19. Private Server Ro .
    How to create your own private Ragnarok-Online server !!! (158)
    I saw that there are a lot of people asking for how to create a private Ragnarok-Online server . so
    now i decide to make this tutorial to to help these people ... i didn't have a server but my
    friend had server and ihelped him to find pros and some tutos so , i learned with him how to create
    a server ...stop making introduction ...let's go ... first you have to have minimum
    requirements : ----Software :---- i think any windows should work, but i recommend Win Xp i
    think you have alredy a Winrar *- Korean Ragnarok client *- Sakray patch (*i recommend the las....
  20. How To Create Embed Image Mail In Gmail
    (54)
    Hi to all ! Anybody can help me to create an email with embedded image so that mail reader
    automatically see that image. Moreover I wont attached that image as it appears small in size in on
    gmail. Thanks in Advance. ....
  21. Best Sport To Watch
    (34)
    I know it's always better to actually play the sport, but most of the time we watch them...we
    should play more, but if you're not playing, which sport do you like to watch most? For me,
    it's, Soccer, woo hoo, or hockey maybe, but the others kinda are boring whilst watching. Add any
    others at will.......
  22. It's A First Day Of The Rest Of Your Life
    HURY PLEASE I CAN'T WAIT MORE (3)
    Who is singing that song??!! It's new and everything I know from this song is just :
    It's the first day of the rest of your life... Also I know that there are man and a woman
    singing that song... Please who knows it please type the full name of that group... or gave an url
    to where I can download it... ....
  23. Slow Internet Browsing With Brand New Computer
    (15)
    I have a brand new computer running Windows XP 512 MB RAM, Compaq Presario 1.4Ghz Celeron. I am
    connected to the internet with Comcast in Fremont. Web sites pages are slow to open up. The
    performance problem occurs on many different sites, so I suspect the problem is on my end -- either
    the computer or my internet connection. It often takes several seconds to open up a link. What
    can I do to fix this? I am not one to be picky about speed, but net browsing is so slow that I
    don't feel like using the computer any more. I've heard some people say that ....
  24. How To Create Java Button Or Frame
    to be customized (14)
    hi to all!!!! just like to ask if it would be possible if i could make a custom
    button or frame in java. i got tired of using the build infeatures in java. i would like to create
    my own dessign of button or frame.. can it be possible!!! /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> thank!!!! /laugh.gif'
    border='0' style='vertical-align:middle' alt='laugh.gif' /> New Help In! is NOT a descriptive
    topic title. Next time you decide not to follow the posting rules, you will be issued a w....
  25. How Can I Create A Gui Using C++
    I need easy steps! (5)
    can someone tell me how to create gui using c++... thanks!!!! /biggrin.gif'
    border='0' style='vertical-align:middle' alt='biggrin.gif' /> Questions do not belong in the
    tutorial section. Moved. Topic names and descriptions are VERY important. Changed that too. Issued
    warning. ....
  26. How To Create A Forum?
    (18)
    I want to create a forum after getting a host on this site,but i cant find a propper program for
    it.Also i want to know how to have polls and other stuff on the side. P0ZzZ! Post moved to the
    right section ....
  27. Rove Live
    How many people here watch it? (10)
    I watch Rove every week. It's one of my favourite shows, and one of the few that I try not to
    miss. My favourite segments are 'What The...?' and 'My Charader'. The new segment
    where Pete's been interviewing people is pretty funny too. Some of my favourite things that
    have happened on the show were when Ranger Stacey brought in all these insects and one of the stick
    insects crawled onto Rove's face /laugh.gif' border='0' style='vertical-align:middle'
    alt='laugh.gif' /> . I also liked when Rove was interviewing Lano and Woodley and they d....
  28. Da Vinci Code
    What's it about?? (16)
    Well I heard in the news abut the Da Vinchi Code and stuff, whats it really about, Like I've
    seen previews and yeah, codes that da vichi used or something, like the How Da Vichin Painted the
    First Supper and if you trace along all the people it says Da Vichi. So I like to Know What The Book
    is about???? Maybe I'll buy it and read it myself....
  29. Whats The Best Code?
    www.bpsite.tk (32)
    Whats you fav code?....
  30. How do you test your php code
    (77)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for dynamic, id, browsing, php, associative, array, create, array, watch, php, code, rest

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for dynamic, id, browsing, php, associative, array, create, array, watch, php, code, rest

*MORE FROM TRAP17.COM*
advertisement



More Dynamic ?id=browsing With Php (associative Array) - Just create array and watch php code do the rest



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE