473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

delete.php?ID=1

pradeepjain
563 512MB
haii,
I have a small security question.I have made php form and hve done addition deletion and edit buttons for the records maintainance(DB records) also.My question is that when a user gets to know the url and plays around wit it say delete.php?ID=1 it directly deletes the record from database..and lke this he can delete all records..how to stop this...


Thanks,
Pradeep
Jul 10 '08 #1
18 5016
chazzy69
196 100+
You didn't really actually specify a question, but i think what your saying is how to stop some from using the url to delete all database records, well when posting to delete.php perhaps you should change the method so that its encrypted and can't be seen i.e. instead of put use post that way its not possible to see which record it is that is been specified to be deleted.

Hopes this helps a little bit to answer your question,
Jul 10 '08 #2
pradeepjain
563 512MB
I am not properly getting u.If u can show me a example i might be able to understand better.

Thanks,
Pradeep
Jul 10 '08 #3
chazzy69
196 100+
My guess is that your using a form to submit to your delete.php page if so, look at the tags for the form, is there one that says method? and is the also one that says enctype?

if so all you should need to do to alleviated your problems is:
set method = "POST" and
set enctype = "multipart/form-data"


hope this helps,
Jul 10 '08 #4
pradeepjain
563 512MB
Yes i use <form method="POST"
Jul 10 '08 #5
chazzy69
196 100+
you are posting a varible of which database number you want to delete right??
if so then if you have method = post and enctype = to what i said above then noby will see what value it is that you are posting in the url bar.

And therefore if your passing a varible called Id, then no one can monkey around with the value in the url bar.

Hopefully this is what you were looking for
Jul 10 '08 #6
Markus
6,050 Expert 4TB
Is this a user submitted form?

If it is, then why shouldn't the user be able to delete all the records?
Jul 10 '08 #7
pradeepjain
563 512MB
hey see
http://xyz.com/delepe.php?ID=43 and this is visible

this is whts stored in browser.so if any one knowing php can get this url he can play rite and i hve not set enctype to anything.yes the user fills the form ..and wht i was talking is of maintainance of data by the admin.he can delete the old records na...


Thanks,
Pradeep
Jul 10 '08 #8
hsriat
1,654 Expert 1GB
Why should the user manipulate a url to delete a record while you have given him a pretty good interface to do the same thing?

If there's a kind of check which you are doing before displaying the "select-to-delete" page (page containing your form) to check whether the user is genuine, just do the same check before running delete.php, so that only authenticated user could reach the delete.php script.
Jul 10 '08 #9
pradeepjain
563 512MB
This is my php script for deleting records

[PHP]<?php

$id=$_GET[Id];
$sql1="delete from abc where ID=$id";

$res_id1=mysql_query($sql1);

if($res_id1== TRUE)
{
echo "Selected record deleted";
}
else
{
$msg = "error while deleting record!!<br><INPUT Type=\"Button\" Name=\"Back\" Value=\"Back\" onclick=\"history.back()\" class=\"button\">" ;
print $msg;
}
?>[/PHP]
Jul 10 '08 #10
Markus
6,050 Expert 4TB
This is my php script for deleting records

[PHP]<?php

$id=$_GET[Id];
$sql1="delete from abc where ID=$id";

$res_id1=mysql_query($sql1);

if($res_id1== TRUE)
{
echo "Selected record deleted";
}
else
{
$msg = "error while deleting record!!<br><INPUT Type=\"Button\" Name=\"Back\" Value=\"Back\" onclick=\"history.back()\" class=\"button\">" ;
print $msg;
}
?>[/PHP]
Like Harpreet said: You must be uaing some sort of check to allow only an administrator to access the delete page (sessions?). Do the same check on delete.php before anything is deleted.
Jul 10 '08 #11
pradeepjain
563 512MB
Hey i hve done for all edit pages and create page it takes them to login page but not for delete page..it takes them to login page but the record is getting deleted also..so i tht this must be something to do with url..and ya i am using drupal tool


Thanks,
Pradeep
Jul 10 '08 #12
hsriat
1,654 Expert 1GB
This is where you are not secure. This means anyone could use your delete.php script.
Don't think POST will work. One who has to misuse your system knows how to create a POST request.

Ideally, you validate a cookie (or session) for every page.
Jul 10 '08 #13
TheServant
1,168 Expert 1GB
If you are using sessions:

Yeah, so anyone who uses the delete.php script must be logged in and be admin:

[PHP]if ($_SESSION['user_name'] = NULL) {
echo("You are not logged in.");
header(location:login.php);
exit;
}
if ($_SESSION['user_type'] != "admin") {
echo("You are authrized to use this.");
header(location:homephp);
exit;
}
[/PHP]

I'm a little wrecked, so my apologies if I have made a mistake, but this is the general thing you should have on protected pages.
Jul 10 '08 #14
hsriat
1,654 Expert 1GB
If you are using sessions:

Yeah, so anyone who uses the delete.php script must be logged in and be admin:

[PHP]if ($_SESSION['user_name'] = NULL) {
echo("You are not logged in.");
header(location:login.php);
exit;
}
if ($_SESSION['user_type'] != "admin") {
echo("You are authrized to use this.");
header(location:homephp);
exit;
}
[/PHP]

I'm a little wrecked, so my apologies if I have made a mistake, but this is the general thing you should have on protected pages.
Your logic is right, but I wonder if header would work after echo. ;)
Jul 11 '08 #15
pradeepjain
563 512MB
thank You all guys for helping me out..since i am using drupal i cld solve the prob..the last sessions script u ppl gave helped me a lot to think of this for me

[PHP]global $user;
if(!$user->uid){
echo("You are not logged in.");
header( 'Location: ?q=user&' . drupal_get_destination() );
exit;
}[/PHP]

Thanks ,
Pradeep
Jul 11 '08 #16
hsriat
1,654 Expert 1GB
thank You all guys for helping me out..since i am using drupal i cld solve the prob..the last sessions script u ppl gave helped me a lot to think of this for me

[PHP]global $user;
if(!$user->uid){
echo("You are not logged in.");
header( 'Location: ?q=user&' . drupal_get_destination() );
exit;
}[/PHP]

Thanks ,
Pradeep
As I already said in the above post, header won't work after echo.
Jul 11 '08 #17
pradeepjain
563 512MB
ok..the msg in echo doesnot get printed ..the header is working fine..anyways i wll remove the echo command.

Thanks,
Pradeep
Jul 12 '08 #18
TheServant
1,168 Expert 1GB
Your logic is right, but I wonder if header would work after echo. ;)
lol, should have seen that... Thanks for the correction tho.
Jul 14 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Chris | last post by:
Hi, sorry to post OT but i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two...
0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
2
by: michael | last post by:
Gotta post because this is driving me nuts. Trying to DELETE orphans. I can successfully: SELECT GroupID FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID IS NULL; but when I...
3
by: Asif Rahman | last post by:
Hi all! Please improve on the following code to make sure the record gets deleted only when the function returns false. Now I see the msgbox, but the record gets deleted no matter the user...
4
by: Ian | last post by:
Hi, I have a problem with delete using where in clause. This is a query: delete from tab1 where id not in (select id from tab2) I calculated costs using select instead of delete: select...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
13
by: mac | last post by:
hi all, im creating a form wich wil upload images to a folder and their names and other details to a database. im able to do uploading but my delete function is not working, please can anybody...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
8
by: harryjohal | last post by:
<?php $host="localhost"; $username="user"; $password="rmypwd"; $db_name="mydb"; $tbl_name="articles"; $cmd=$_GET; $id=$_GET;
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.