Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
help with php and html
Old 05-16-2010, 08:03 PM help with php and html
Junior Talker

Posts: 1
Trades: 0
im trying to make my links open in the same page with html and php includes... i need some help. My links are like this <a href="index.php?id=test">Test Link</a>. I want each link that i type to open up in my php include...so basically I want the php include to open any html file as long as it has the correct id to the name of the file. I need the code if anyone can help and if possible make it where index.php opens the news page.
stevo4200 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-17-2010, 01:51 AM Re: help with php and html
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
PHP Code:
//check here to make it is correct name
if($_GET['id']!='test')
    die(
'invalid data');

include 
$_GET['id']; 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 05-17-2010 at 07:55 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 05-17-2010, 04:17 AM Re: help with php and html
Experienced Talker

Posts: 48
Name: Websys_seo
Location: India
Trades: 0
well it's simple,
just check it whether id requested do exist or not if not then redirect it to your desired page, but remember one thing that you will have many ids in future as you will increase your pages, so the above suggestion will not help you out. In that case you need to cross check it with your database.
/*suppose you are having a table with name pageinfo which is having a field page_id */

$id=$_GET['id'];
$sql= "select * from pageinfo where page_id='".$id."'";
$rs=mysql_query($sql);
$count=mysql_num_rows($rs);
if($count!>0)
{
header("Location=yourpage.php")
}
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Arings is offline
Reply With Quote
View Public Profile Visit Arings's homepage!
 
Old 05-17-2010, 07:32 AM Re: help with php and html
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
AND check that the ID does NOT contain a reference to an external source.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-17-2010, 07:57 AM Re: help with php and html
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
Originally Posted by chrishirst View Post
AND check that the ID does NOT contain a reference to an external source.
ps. the code I wrote above in my previous post does this check.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 05-17-2010, 09:55 AM Re: help with php and html
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by nayes84 View Post
PHP Code:
//check here to make it is correct name
if($_GET['id'])!='test')
    die(
'invalid data');

include 
$_GET['id']; 

Quote:
Originally Posted by nayes84 View Post
Quote:
Originally Posted by chrishirst View Post
AND check that the ID does NOT contain a reference to an external source.
ps. the code I wrote above in my previous post does this check.
How??
The code only checks that the value is NOT equal to 'test'
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-17-2010, 07:53 PM Re: help with php and html
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
Originally Posted by chrishirst View Post
How??
The code only checks that the value is NOT equal to 'test'
I understand you meant security measures to avoid code injection.

Checking on 'test' means it can't be any thing other than 'test'

For example if $_GET['id'] equals http://badsite.com/badscript.php

Running
PHP Code:
include $_GET['id']; 
Without checking on id can be very dangerous. So checking if id has certain values like 'test', 'foo' or any valid name is important. Isn't that what you mean?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 05-17-2010 at 07:54 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 05-18-2010, 09:37 AM Re: help with php and html
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Checking on 'test' means it can't be any thing other than 'test'
Correct, but what if the end user need more than a page called 'test'

While your code will work for one instance and will need editing and extending to cover each page that is added.

Code that will block potentially malicious includes (anything external) while checking that a local page exists with that name will make the code flexible and extendable.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-18-2010, 01:24 PM Re: help with php and html
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Correct, but what if the end user need more than a page called 'test'

While your code will work for one instance and will need editing and extending to cover each page that is added.

Code that will block potentially malicious includes (anything external) while checking that a local page exists with that name will make the code flexible and extendable.
Correct. but doing that will make another vulnerability in the code.

1- Limiting it to just local files doesn't mean it is 100% safe because it can be used to view protected files or non php files. like perl or cgi which will show the code directly if included in php file ex: include '/home/username/public_html/perlcode.cgi'

2- another thing is if $_GET['id'] for example equals '/secured-zone/secured-data.txt' assuming secured-data.txt file has important users information like passwords or even login information to some services in the server itself. doing checks if file is local only will not detect such an attack and will result in the server getting hacked.

3- can be used to execute uploaded files like uploading a file using some other upload form in the same site/server. doing so place that file in /tmp directory or /home/username/tmp. that file can be remain undeleted if not handled properly by the uploader script.
anyway having such a bug with allowing included using $_GET['id'] as an argument for the file can allow the intruder to upload a file and execute it on the server.

That are only 3 vulnerabilities that I thought of while replying you but I think there are more to mention.

Flexibility & Extendability are a good thing to do but making sure the script secured is much more important, I think.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 05-18-2010 at 01:26 PM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Old 05-18-2010, 02:02 PM Re: help with php and html
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Yep all possible, provided the "attacker" knows what files exist and their location. and of course that the script developer has not restricted what local folders can be specified.

When coding scripts like this only a file name should be allowed for a local reference and a predetermined folder path added to the file name.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-20-2010, 08:17 AM Re: help with php and html
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
Correct!
And better, if includes are allowed only from a pre-written list either inside the php file itself or in a database. this could limit files to exactly the files allowed for inclusion.
But anyway this would contradict with your script flexibility standard. lol

In short it is a trade off between security and flexibility.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");
nayes84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to help with php and html
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.42202 seconds with 12 queries