Jump to content

[SOLVED] Identify server that posted data. Is this possible?


nevesgodnroc

Recommended Posts

I am looking into the security aspects of a site, and would like to know if there is any way to identify the source of the data that is posted to the php page responsible for processing the data.

 

in other words I only wantt he php code to process the data if the data was posted from a form hosted on my server.

 

any help on this would be greatly appreciated. Thank you

Link to comment
Share on other sites

actually my first code would not have worked any way - I just tested it, but the code below will work.

 

<?php

$mydomain="yourdomain.com";  // change to your domain name

$url = $_SERVER['HTTP_REFERER'];

$domain = parse_url($url);

if ($domain[host] != $mydomain) {
echo "<h1>Authorization Denied</h1>";
exit;
}
else {
// process form action
echo "Processing Complete";
}

?> 

 

 

PS: teng84 - just for fun - just wasting time too and yes I did use $_SERVER['HTTP_REFERER'] in this script because this person is wanting to prevent forms from outside his/her domain from accessing his/her processing script - so yes that would work in this situation.  :)

 

yeah, yeah, yeah - miss print - I was trying to beat you to the draw  ;D

 

y? i dont care !  all i do is post my ideas to waste my time!

Link to comment
Share on other sites

That is Great but I want to be able to stop some one from being able to view the source tehn save it to their PC and run it from there.  If they view the source the will get all the info they need to iether run my exact form with a few modification from their PC or from any other server.

 

Maybe I am looking at theis the wrong way.  What if I blocked being ableto view the source?

huh

Link to comment
Share on other sites

You can't reliably block the source from being viewed. The best option is to set a $_SESSION variable on your form page, then check for its existence on the process page. $_SERVER['HTTP_REFERER'] is unreliable at best as it can easily be spooked or not sent at all.

Link to comment
Share on other sites

You can't reliably block the source from being viewed. The best option is to set a $_SESSION variable on your form page, then check for its existence on the process page. $_SERVER['HTTP_REFERER'] is unreliable at best as it can easily be spooked or not sent at all.

 

I never thought of that before. Sessions are a great idea! And a session-based captcha would be a further security.

 

Sessions *almost* guarantee your server originated the form that the user is submitting.

Link to comment
Share on other sites

Yes I think that teh session will work for me.

 

Let me make sure my thought behind it is correct though.

 

At the top of my form to submit I will start a session and set some session variable to 'a value'

on the script processing page before processing script i check if $_SESSION[somevar] == 'a value'

 

Is that right?  I am at work right now and i cannot tranfer files up to my server in order to test it out.

 

Also Sessions are new to me and I have only just read a couple of tutorials on them. Could anyone tell me how the server knows that the user has closed the browser. Or maybe a place were i can read up more on how sessions work  I like to have a good understanding of things before i put them in my code.

Link to comment
Share on other sites

Yes I think that teh session will work for me.

 

Let me make sure my thought behind it is correct though.

 

At the top of my form to submit I will start a session and set some session variable to 'a value'

on the script processing page before processing script i check if $_SESSION[somevar] == 'a value'

 

Is that right?  I am at work right now and i cannot tranfer files up to my server in order to test it out.

 

Also Sessions are new to me and I have only just read a couple of tutorials on them. Could anyone tell me how the server knows that the user has closed the browser. Or maybe a place were i can read up more on how sessions work  I like to have a good understanding of things before i put them in my code.

 

At the top of the form page (before any output), you must have this PHP code:

<?php
session_start();
$_SESSION['var'] = "your-form";
?>

This type of session does not save data as a cookie, and is not a "persistent session". The session will automatically end when the user's browser is closed. By 'end', I mean the browser will not remember the session id any more.

 

In the form processing script, put this at the very beginning:

<?php
if (!isset($_SESSION['var'])) {die("You didn't use my form!");}
?>

 

Links: http://pksml.net/search/php+sessions+tutorial

Link to comment
Share on other sites

Thank you,

 

I'm happy that you took time to anser my question.

You must be very dedicted to this forum if you are ansering replies on Thanksgiving

 

Staying at home this year. Between cleaning house and helping with dinner, there's plenty of time for PHP fun!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.