Jul 27, 2008

Dealing With Links Like ?id=123 - pls help in a small issue

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

free web hosting

Dealing With Links Like ?id=123 - pls help in a small issue

apple
While dealing with such a links in php
CODE
page.php?id=1

i dont want that someone access this page directly using page.php..
i can give some custom message incase someone try to access page like:
CODE
page.php
okay i can make it by using if condition etc..
but the other problem is that, if someone try to access like,
CODE
page.php?id=
in this case (where id is not given, but there's only "?id= " which makes no sense.. in that case i want to make some custom msg etc. how i can handle this situation?
Regards


Reply

matak
maybe u should try using .htacces, for redirecting page.php to another page. i really don't know proper code to do that but someone else here might know (i'm also interested in that .htaccess code happy.gif )

Reply

jlhaslip
One method is to define an array of suitable values.
In the following snippet, I have defined an array which I use on a small site.

CODE
$data_array = array('index', 'one', 'two', 'three', 'four', 'five', 'contact');


And then I use the following block of code to make sure the "?page=" contains one of those array elements or they get redirected to the index.php page.
Your example uses "?id=", so you will need to modify that. And also, this code block needs some further security added to it, and as you can tell, I include files with ".txt" file extensions. (Included files always parse as html. Add the php tags inside them if they contain php code) The file extensions will need to be altered to the file extension you use.
Small changes, really.

CODE
$submit = $_GET[page];
echo  $_GET[page];                                                 // echo to confirm the value as a test only

if( !isset($_GET[page])   ) {                            // page is not set , use first array element
                if (file_exists($data_array[0] . '.txt' )) {
                include ( $data_array[0] . '.txt' );
                }  
                else {
                    include ('index.txt');               // or default to index page if first file doesn't exist
                }
        }
        elseif (in_array($submit , $data_array)) {       // value is in array
                if (file_exists($submit . '.txt' )) {    // and exists
                include ( $submit . '.txt' );
                }
                else {
                    include ('index.txt');              // default to index page
                }
        }
        else {                                                                     // value is not in array
                if (file_exists($data_array[0] . '.txt' )) {    // and first array name exists
                include ( $data_array[0] . '.txt' );
                }
                else {
                    include ('index.txt');                     // or use index page
                }
        }


If you follow the script logic, the default page which is included is the index page. Other values must be contained in the defined array.
As you add pages, simply add an element to the array defined above.

There are other methods to use, just thought you might like to see this one and I had it handy. smile.gif
Hope this helps.

 

 

 


Reply

galexcd
When checking the variable ID, are you using the isset function or are you checking if the string == ""?

Using string=="" should work if ?id= is enterned and no number.

Reply

mahirharoon
this is the correct code

CODE
<?php

$variable = $_GET['id'];

switch($variable) {

default: include('home.php'); break;
case "forum": include('forum.php'); break;

}

?>

instructions:
CODE
case "forum": include([u]'forum.php'[/u]); break;
= change - forum.php to the url

forum - change to your id (underlined) which will come in
CODE
index.php?id=[u]forum[/u]


CODE
$variable = $_GET['id'];
-change id to what you want here (underlined) index.php?id=123

Reply

pop
what happens if case isn't forum? if it si something else. will it for sure go to default value, or ?

thanks

Reply

rvalkass
If it can't find a case to match the value in the variable, it will display everything in the default section. So, with the example above, if $variable is not equal to forum then the default case is displayed.

Personally I would put the default case last. I'm not sure if it makes a difference but it seems to be pretty much standard, unless you are using the fall-through method.

Reply

online
CODE
<?php>
if {get=[id=1]
}else{
header location = page.php
?>

something like that ....(sorry for my php scripting...i had a bit of hurry)

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 : dealing, links, id, 123, pls, small, issue

  1. A Small Social Networking Site....
    as a part of college project (9)
  2. I Can && Cannot Acces My Website
    Confusing issue. (4)
    I am a hosted member in trap17 and my domain is www.karunya.cc . I have been not able to access my
    website for few days and i had PM'd the admin and he provided me great support,but still i have
    some confusion , so please anyone help me . My domain was now accessible using my true IP . On the
    other hand if i use a Proxy i am able to access my website , so i had given my true IP's
    220.225.140.98, 210.212.244.4 to Xisto to check whether they are in the IP ban List in Xisto
    firewall , the internet im using is provided by my college and im sure here there is not ....
  3. Flash Wmode(transparent) Pramater In Firefox3(on Linux) - Not Working
    issue with flash transparancy and firefox3( on linux op. sistem) (1)
    Can anybody help me... Unfortunately I have an issue with firefox2-3 (under linux (ubuntu)
    operating sistem) and flash transparacy... The site structure is: Menu (dropdown with javascript)
    and under that a big flash with wmode=transparent param enabled.. On mouse-over the menu is not
    appearing because the flash hides it... With all other browsers it works. I understood that this
    is a flash plugin bug under linux - firefox2-3 Does anyone has a solution?....
  4. Can't Access My Site....weird Issue
    (5)
    Okay, so last night everything worked fine. I loaded up cpanel, fixed issues with the site after the
    database move, etc. Today I'm unable to load up the site. It just keeps giving me ping
    timeouts. With what I'm being told by others it is only me having this issue with my site, and
    yet there have been 0 changes to my pc between it working and not. I have tried multiple times
    during the day with no luck. Along with this, if I load my website using a proxy service then I do
    not have any issues. The only time it will not allow me to access it is if I am "using" my....
  5. Gemzar® Plus Second Chemotherapy Agent Provides Small Survival Benefits In Advanced Pancreatic Cancer
    Pancreatic cancer news (0)
    QUOTE Gemzar® plus Second Chemotherapy Agent Provides Small Survival Benefits in Advanced
    Pancreatic Cancer According to results recently published in the journal Drugs and Aging, the
    combination of Gemzar® (gemcitabine) with a second chemotherapy agent provides small but significant
    improvements in survival compared with Gemzar only in the treatment of metastatic pancreatic cancer.
    The pancreas is an organ surrounded by the stomach, small intestine, bile ducts (tubes that connect
    the liver to the small intestine), gallbladder, liver, and spleen. The pancreas helps....
  6. Dealing With A Very Bad Break Up & Desperate For Some Caring Help
    (2)
    I was just dumped by my boyfriend of a year and a half. I was his first girlfriend, he was my first
    boyfriend - we shared pretty much all of our firsts together. He even told me he wanted to get
    married. We were so serious that I decided to take a year off after graduation so that we could go
    to college together because he is a year behind me. I just graduated from high school about two
    weeks ago. He broke up with me about a week ago after another fight. We had fought a lot before,
    and had broken up many times before but always managed to get back together in 24 ho....
  7. Issue With Windows Vista - Sound Card Acting Wierd [resolved]
    Sound card doesnt recognize my 5.1 (4)
    For some strange reason My sound card doesn't seem play sound on my 5.1 properly. I've a
    dual boot system. on XP its running properly. So I figure this is an issue with Vista only. My
    sound card is recognized as Realtek HD audio. *(My motherboad is XFX 650i Ultra) Now whenever a
    jack on the back-panel is unplugged or plugged in it shows and alert and gives an option window
    under XP where I can select what I've put. It somewhat allows me to configure any pin to be a
    input or output. However I could not find this same option in Vista. I generally don....
  8. Registration Form?!
    Password Issue??? (6)
    How can I build the registration form with some additional function which is illustrated by attached
    file. When a user tries to type a password, that bar thing says neither it's strong nor weak, or
    medium. Just take a look at attachment....
  9. Overpopulation
    Overpopulation a growing issue, how should we deal with it? (7)
    Overpopulation is a growing issue in our world that must be dealt with. But how? Animals and Humans
    are both organisms in this world however the things we do to animals to control their population in
    general wouldn't be considered humane; that is if the same methods were used on humans. Our
    world is growing exponentially and very quickly, million of people are born each day. Of course many
    people die each day too but our population is growing faster than it is declining. As a human
    species we have developed many different ways with dealing with overpopulation. For ....
  10. Dealing With Lined Skin
    (0)
    Fatigued skin comes about easily especially if you are a college student or busy working person who
    has to burn the midnight oil and lead a stressful lifestyle. When your skin is fatigued, you start
    developing lines around your eyes and forehead, which is usually a result of dehydration. To
    distinguished between dehydration lines and wrinkles, push gently against the lined area with your
    finger. If the lines are fine and they disappear or become less apparent when you release your
    finger, they are marks of dehydration. If not, they are wrinkles and more difficult to tac....
  11. Photoshop, Flash And Fireworks Tutorial Site Links
    This has a huge links of useful sites (0)
    Adobe Photoshop Tutorials http://www.rainworld.com/psworkshop/
    http://www.reality9.com/tutorials.html http://www.spoono.com/
    http://www.stridingstudio.com/tutorials/ http://www.designsbymark.com/pstips/index.html
    http://geda-online.com/tutorials.htm http://www.thewebmachine.com/
    http://www.extremephotoshop.com/tutorials.aspx
    http://www.thinkdan.com/tutorials/photosho...-tutorials.com/
    http://www.designerslounge.org/tutorials/ http://www.eyesondesign.net/pshop/tuts.htm
    http://www.eyeball-design.com/fxzone/tutorial.htm http://user.fundy.ne....
  12. Dealing With Parents
    overly aggressive (7)
    Well most of you may not know my age but I am old enought to call my self a parent. My vent is
    regarding issues with other parents and sports. My son is playing little league baseball, T-ball
    division, yes this is the age group that runs to the pitcher and sometimes after the ball while
    standing on base and even after hitting the ball. This is the age division where it should all be
    about fun. As a matter of fact we do not even keep track of a score. But what I dislike is the fact
    that parents in this division are so aggressive. they are constatntly yelling and get ....
  13. Computinghost 3s Order Issue (paypal).
    (3)
    Is there any way to resolve PayPal's most recent annoyance? I went to the trouble of getting
    the money into PayPal from bank so I can pay instantly, bu when I go to order it wants to do this
    eCheque rubbish and take more money out of the bank instead of PayPal.....
  14. Transfer Information Via Links With Php
    Please Help! (2)
    I need to send a piece of information from one php page to another (kind of like a form). The thing
    is that I need the page to send a different piece of information based on what link is clicked.
    Something like this: CODE <a href="some code">Send Information 1</a>
    <a href="some other code">Send Information 2</a> I don't know how to
    do this, so does anyone have any ideas? Thanks in advance! /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  15. Ie 7 Issue With Ajax
    Some ajax calls dont seem to work (2)
    function reload_char() { race_id = Ext.get('race').dom.value; gender =
    Ext.get('race_gender').dom.value; face = Ext.get('race_face').dom.value; hair_id =
    Ext.get('race_hair').dom.value; // race race_letter =
    Array('H','E','T','M','G'); race = race_letter ; /*
    //gender if(race == 'G' || race == 'M') { gender = ''; } //hair
    if(hair_id == 1) { hair = 'a'; } else { hair = 'b'; } image =
    '80px-'+race+gender+face+hair+&....
  16. *** Virus Alert *** Important ***
    *** DO NOT TOUCH THESE LINKS *** (14)
    Sources have warned that the following links, or similar, should not be "touched" or linked to.
    Your Anti-virus will issue a severe warning if you click to these links. It would appear that the
    common element is the filename in the link which follows the web protocol h t t p. h {double t} p
    {colon} //xxthebestxx.hut2.ru/ r57.txt h {double t} p {colon} //www.hdcs.org.np/ r57.txt
    h {double t} p {colon} (a file on your account) %20script:void(0) h {double t} p {colon}
    //turkey.dnsdc9.com/~activ7/ r57.txt h {double t} p {colon} //turkey.dnsdc9.co....
  17. A Small Html Problem
    How to display foreign characters correctly when designing a site. (4)
    I was wondering how I could solve a small problem. I was told that some people see accented and
    umlauted letters (such as " é " and " ë ") as question marks (" ? ") on my website. I come across
    the same thing sometimes when looking at websites which use non-English characters. Funnily enough,
    the other day, I looked at a site and the apostrophy ( ' ) was also shown as a question mark.
    That is a very common character usually, I would think. I thought it had something to do with the
    character encoding settings, and let me also mention I use Mozilla Firefox as my brows....
  18. Loss, Grief And Mourning
    Dealing with death (8)
    I have a poem on my sight that addresses this subject matter. I thought this would be an
    appropriate place to post a link in the hope that it might comfort someone. Gone From My Site
    ....
  19. Linksys Befw11s4 Wireless Router Issue
    it is usual?? (11)
    I have an linksys wireless router Befw11s4 and my doubt is: it is normal that my router freeze, and
    i have to restarted, and why it hapend....
  20. Dealing With A Long Term Relationship Break Up
    How do I deal with this? (25)
    I've been going out with this guy for about 2 years now, and for the past 1 or 2 months he was
    acting a bit weird. A couple days ago he told me he didn't want to be in a relationship, he
    wanted to be single, beacause he's been in serious relationships for a quite a while, so he just
    wanted to have some time to himself. Well, with the help of a friend of mine and his, I found out
    he's going out with this other girl, and he's been thinking about a serious relationship
    with her for a while...and I don't know if he actually waited untill I was out of ....
  21. Dell Tech Support
    I just needed a small bit of info (22)
    Ok, so I got my aunt's old Dell Inspiron 8000 laptop. She also gave me a wireless card with it,
    but I had to promise her that I wouldn't connect to the Net until I reinstalled Windows. I
    needed to open the BIOS Setup program to change the boot order of the DVD-ROM drive, but I just
    couldn't figure out how (even hitting Fn+F1, where F1 is marked setup, didn't work, and I
    tried about half a dozen other key combonations, which also failed to work). So this morning I
    called Dell, with hopes of getting my problem solved. The crazy lady whose accent I couldn....
  22. Get Paid To Post On Forums?
    Links, Resources for Pay for Writing, Earn from Forums (17)
    Get Paid to Post on Forums I have seen these all over, could people maybe give me a
    short list on where I could post on forums and get paid? I am a freelance writer, and I know this
    is one option. I tried searching it, but word of mouth always works best. Thanks in advance!
    Note: Please move if needed, I wasn't sure if I should do it in the Make Money forum, or not.
    At Trap17.com - This very site, You get paid in terms of CREDITS. These credits are used to keep up
    your Web Hosting account (which we give for FREE). The Web Hosting is of top ....
  23. Make Money Clicking On Links
    50 Cents Per Click (5)
    GUYS MAKE 50 CENTS PER CLICING ON A LINK HERE>> QUOTE click here1 click here 2 click
    here 3 click here 4 click here 5 click here 6 click here 7 click here 8 click here
    9 click here 10 click here 11 click here click here 12 click here 13 click here
    14 click here 15 click here 16 click here17 click here18 click here19 click here
    20 Long lists need to be in quote tags. Please read the trap17 readme. And I have moved the
    other duplicate post to SPAM. http://www.trap17.com/forums/index.php?showtopic=371....
  24. Simple C File Handling In Action
    Small code snipet which covers most of basic file handling and navigat (3)
    Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
    formalities to get the code review incorporated and update all source code files with code review
    headers. Imagine if you need to open 300 files one by one and append code review headers at the
    end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
    in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
    utility to open all files passed on command line and open attach code review headers an....
  25. 10.000's Of Icons, Excellent Collection!
    5 rapidshare links for all. (14)
    This 5 Collections have so many and so many icons that i don't have the time to describe it.
    Download the best collection of icons of the entire Internet (my collection, he he) ---------------
    Download the icons packs from here: http://free-icons.freehostia.com or from here: Icon
    Collection 1 (31577572 Bytes) Download:
    http://rapidshare.com/files/18066342/10.00...tion.1.rar.html Icon Collection 2 (24978943 Bytes)
    Download: http://rapidshare.com/files/18075936/10.00...tion.2.rar.html Icon Collection 3
    (27731070 Bytes) Download: http://rapidsh....
  26. Dreamweaver Permissions Issue
    Access denied when trying to FTP (5)
    Okay, so I was trying to FTP these files over dreamweaver today... and it seemed to be working fine.
    But then, certain files won't let me transfer from my hard drive to the internet, or the other
    way around. It gives me this error message: QUOTE An FTP error occured - cannot put form1.html.
    Access denied. The file may not exist, or there could be a permission problem. Anyway, I know
    that the file does indeed exist. I've opened it on my hard-drive... and it is there. But it
    won't let me upload this one or certain other ones with the FTP. So I went o....
  27. Creating Links In Images
    Using ImageReady (17)
    In this tutorial I will show you how to create links in your image. I'm shore there's a lot
    of different ways you can do this, but I'll just show you how to do it real easy. 1) After
    creating the image you want to add links to in photoshop, make shore the mode is set to RGB Color.
    Just go to Image -> Mode -> RGB Color. 2) Go to File -> Jump To -> Adobe ImageReady. Your image
    will now load into ImageReady. For this tutorial I will be using this image that I found: I will
    make the buttons of this navigation bar into links. 3) Press K to select the slice t....
  28. Internet Explorer Issue...
    mysterious closes (10)
    Hopefully I am not the only one experiencing this, and one of you can help me figure it out... I run
    a cable modem, so I surf the web using IE... However, every so often, generally right when I am
    doing something important as my luck goes, all of a sudden every IE window closes without giving any
    reasoning or error messages... Does anyone know either how to fix it, or why this happens? I am not
    using a proxy, router, or anything like that, and my PC is virus free, and scanned each day for
    ad/spyware... any ideas?....
  29. Sendearnings.com
    Get paid to read emails and click on links (14)
    Send Earnings Basically, you can make a new e-mail account and sign up on this site, entering
    in the new e-mail and information. They will then send you a couple of e-mails a day from various
    advertising companies. All you need to do is open up the e-mail, click on the link inside of it, and
    read the page. You receive 1-10 cent's for every link you click/e-mail you read, and receive
    $5 for every friend you introduce to the site, with your recruiting link. You can supposedly
    earn hundreds of dollars per month. Another bonus, is that they are currently havi....
  30. What's Your Favourite Book? Why?
    A small investigation about most popular books (94)
    The question is very simple, what is your favourite boook? And why? I have also added a small pool
    about how many books do you read each year. Anyway my favourite is L.A. Confidential written by
    James Ellroy. It's a very good police story with a intriguing plot, but it's also a
    masterpiece of politic and social analize. The power games of institutions, the corruption that have
    attacked police and government and the general undeground atmosphere are the pillars fo this
    beautiful book. It isn't a simply police book, but a fresco of a society and of a period of ....

    1. Looking for dealing, links, id, 123, pls, small, issue

Searching Video's for dealing, links, id, 123, pls, small, issue
Similar
A Small
Social
Networking
Site.... -
as a part of
college
project
I Can
&&
Cannot Acces
My Website -
Confusing
issue.
Flash
Wmode(transp
arent)
Pramater In
Firefox3(on
Linux) - Not
Working -
issue with
flash
transparancy
and
firefox3( on
linux op.
sistem)
Can't
Access My
Site....weir
d Issue
Gemzar® Plus
Second
Chemotherapy
Agent
Provides
Small
Survival
Benefits In
Advanced
Pancreatic
Cancer -
Pancreatic
cancer news
Dealing With
A Very Bad
Break Up
&
Desperate
For Some
Caring Help
Issue With
Windows
Vista -
Sound Card
Acting Wierd
[resolved] -
Sound card
doesnt
recognize my
5.1
Registration
Form?! -
Password
Issue???
Overpopulati
on -
Overpopulati
on a growing
issue, how
should we
deal with
it?
Dealing With
Lined Skin
Photoshop,
Flash And
Fireworks
Tutorial
Site Links -
This has a
huge links
of useful
sites
Dealing With
Parents -
overly
aggressive
Computinghos
t 3s Order
Issue
(paypal).
Transfer
Information
Via Links
With Php -
Please
Help!
Ie 7 Issue
With Ajax -
Some ajax
calls dont
seem to work
*** Virus
Alert ***
Important
*** - *** DO
NOT TOUCH
THESE LINKS
***
A Small Html
Problem -
How to
display
foreign
characters
correctly
when
designing a
site.
Loss, Grief
And Mourning
- Dealing
with death
Linksys
Befw11s4
Wireless
Router Issue
- it is
usual??
Dealing With
A Long Term
Relationship
Break Up -
How do I
deal with
this?
Dell Tech
Support - I
just needed
a small bit
of info
Get Paid To
Post On
Forums? -
Links,
Resources
for Pay for
Writing,
Earn from
Forums
Make Money
Clicking On
Links - 50
Cents Per
Click
Simple C
File
Handling In
Action -
Small code
snipet which
covers most
of basic
file
handling and
navigat
10.000's
Of Icons,
Excellent
Collection&#
33; - 5
rapidshare
links for
all.
Dreamweaver
Permissions
Issue -
Access
denied when
trying to
FTP
Creating
Links In
Images -
Using
ImageReady
Internet
Explorer
Issue... -
mysterious
closes
Sendearnings
.com - Get
paid to read
emails and
click on
links
What's
Your
Favourite
Book? Why? -
A small
investigatio
n about most
popular
books
advertisement



Dealing With Links Like ?id=123 - pls help in a small issue



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web 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