Jump to content

looking for a simple php code


twinklerip
 Share

Recommended Posts

there are gonna be 2 inputs, catid & pagemun... switch satement can be used.if catid=2 and pagenum=1 then it'll show some htlm code stored in a file named pm2_1.txt, if catid=2 & pagenum=2 then the file ud be pm2_2.txt and so on...can any one help me?<html><head>....</head><body>........<div><?php codes (nested switch)?></div>........</body></html>

Link to comment
Share on other sites

If I understand right, you are asking for a way to include two input values into a string which will then be the name of a web site that is loaded. I would do it somehow like this (in pseudo-code):

Validate catid and pagenum    If validated, make string with URL from catid and pagenum, and load page from string    Else, show error message (or default page)

When doing sensitive tasks (like file i/o, database access, and loading pages) based on user input it is always advisable to validate the input to make sure it is like expected. Otherwise, it could be an invitation to the 'bad guys' out there to execute bad script on the server.I would validate catid and pagenum by using the function ctype_digit() to check that they are integers, and also check that they are within the number range expected (or at least not null). Then I would define a string and put catid and pagenum into it together witht the other text needed to make the name of the file. Finally I would load it using a require().I hope this helps :) If there is anything else, let us know.

Link to comment
Share on other sites

there are gonna be 2 inputs, catid & pagemun... switch satement can be used.if catid=2 and pagenum=1 then it'll show some htlm code stored in a file named pm2_1.txt, if catid=2 & pagenum=2 then the file ud be pm2_2.txt and so on...can any one help me?<html><head>....</head><body>........<div><?php codes (nested switch)?></div>........</body></html>

What you could do is:
// Get catid and pagenum$catid=2;$pagenum=2;//Make sure they're only numbers, and then include the file pm{catid}_{pagenum}.txtif(is_numeric($catid) & is_numeric($pagenum))include('pm'.$catid.'_'.$pagenum.'.txt');

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...