Jump to content

[SOLVED] Newbie looking for help before I pull out my hair


Recommended Posts

Hello all, I am a newbie to php and I am trying to get something that I am sure is simple to work. Think that I am too close to the fire or just simply over thinking the solution.

 

K here is the problem that I am needing help with. I have a web form with java that I need to capture the ip address of the person who is filling out the form. I have scoured the web and think that I am simply missing what is right in front of my eyes. Here are the scripts that I am working with.

 

PHP part:

 

<?php

 

if ( !isset($_SERVER['SPI'])) {

        die();

}

 

if (!isset($_SERVER['DOCUMENT_ROOT'])) {

echo("CRITICAL: we seem to be running outside of the norm.\n");

header("Location: http://".$_SERVER["HTTP_HOST"]."/");

die("CRITICAL: Document root unavailable.\n");

}

 

$request_method = $_SERVER["REQUEST_METHOD"];

if($request_method == "GET") {

$query_vars = $_GET;

}

elseif ($request_method == "POST") {

$query_vars = $_POST;

}

reset($query_vars);

 

function customsort($a,$b) {

// $a is array for form vars, $b is comma seperated case sensitive field order

// this is case sensitive -- good idea to hrc that.

        $data = array();

        if ( strstr($b,',') == FALSE )  {

                $b = $b.",";

        }

        $ordering = split(',',$b);

        foreach ($ordering as $orderitem) {

                if ( ($orderitem != null) && ($orderitem != "") ) {

                        if (isset($a[$orderitem])) {

                                $data[$orderitem] = $a[$orderitem];

                        }

                }

        }

        foreach ($a as $key=>$val) {

                $data[$key] = $a[$key];

        }

        return $data;

}

 

function xmlentities($string) {

return str_replace ( array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $string);

}

 

$t = date("U");

 

$logged_string = $_SERVER['REMOTE_ADDR'] . "|" . date("j M Y g:i a");

$file = fopen("userIP.log", "a");

fputs($file, $logged_string, strlen($logged_string));

fclose($file);

 

$formhomedir = preg_replace('/.*\/home\/content/','',$_SERVER['DOCUMENT_ROOT']);

$formhomedir = explode('/',$formhomedir);

$formhome="/home/content".$formhomedir[0]."/".$formhomedir[1]."/".$formhomedir[2]."/".$formhomedir[3]."/".$formhomedir[4]."/data/";

 

$file_order = ".default";

$file_format = ".text";

$file_interval = ".15m";

$field_order = "";

 

if (isset($query_vars['form_order'])) {

if ($query_vars['form_order'] != "alpha") {

$field_order=$query_vars['form_order'];

$file_order=".custom";

$query_vars = customsort($query_vars,$field_order);

}

else {

switch ($query_vars['form_order']) {

case "alpha":

uksort($query_vars,'strnatcasecmp');

$file_order=".alpha";

break;

default:

$file_order=".default";

break;

}

}

}

 

if (isset($query_vars['form_format'])) {

switch ($query_vars['form_format']) {

case "csv":

$file_format = ".csv";

break;

case "html":

$file_format = ".html";

break;

case "xml":

$file_format = ".xml";

break;

case "text":

case "default":

default:

$file_format = ".text";

break;

}

}

 

if (isset($query_vars['form_delivery'])) {

switch ($query_vars['form_delivery']) {

case "hourly":

$file_interval = ".60m";

break;

case "hourly_digest":

$file_interval = ".60mc";

break;

case "daily":

$file_interval = ".24h";

break;

case "daily_digest":

$file_interval = ".24hc";

break;

case "digest":

$file_interval = ".15mc";

break;

case "default":

default:

$file_interval = ".15m";

break;

}

}

$file = $formhome."form_".$t.$file_order.$file_format.$file_interval;

$fp = fopen($file,"w");

 

switch ($file_format) {

case ".csv":

$csvkeys = "";

$csvvals= "";

$firsttime = "";

while (list ($key, $val) = each ($query_vars)) {

if ( ($key == "form_order") ||

($key == "form_format") ||

($key == "form_delivery") ||

($key == "redirect") ) {

}

else {

if ($csvkeys != "") {

$firsttime=",";

}

$tmpkey=escapeshellcmd($key);

$csvkeys = $csvkeys.$firsttime."'".$tmpkey."'";

$tmpval=escapeshellcmd($val);

$csvvals = $csvvals.$firsttime."'".$tmpval."'";

}

}

fputs($fp,"$csvkeys\n");

fputs($fp,"$csvvals\n");

break;

case ".html":

fputs($fp,"<table border=\"1\" cellspacing=\"1\" cellpadding=\"2\">\n");

break;

case ".xml":

fputs($fp,"<form>\n");

break;

}

 

while (list ($key, $val) = each ($query_vars)) {

if ($key == "redirect") {

$landing_page = $val;

}

if ( ($key == "form_order") ||

($key == "form_format") ||

($key == "form_delivery") ||

($key == "redirect") ) {

 

}

else {

switch ($file_format) {

case ".html":

fputs($fp,"\t<tr>\n");

fputs($fp,"\t\t<td><b>$key</b></td>\n");

fputs($fp,"\t\t<td>$val</td>\n");

fputs($fp,"\t</tr>\n");

 

break;

case ".csv":

// content is already output

break;

case ".xml":

fputs($fp,"\t<field>\n");

fputs($fp,"\t\t<fieldname>".xmlentities($key)."</fieldname>\n");

fputs($fp,"\t\t<fieldvalue>".xmlentities($val)."</fieldvalue>\n");

fputs($fp,"\t</field>\n");

break;

case ".text":

default:

fputs($fp,$key.": ".$val."\n");

break;

}

}

}

 

switch ($file_format) {

case ".html":

fputs($fp,"</table>\n");

break;

case ".xml":

fputs($fp,"</form>\n");

break;

}

 

 

fclose($fp);

 

if ($landing_page != "") {

header("Location:  http://www.cssc-claims.com/claimtrackerpro/ctp-main.htm" );

}

else {

header("Location:  http://www.cssc-claims.com/claimtrackerpro/ctp-main.htm" ) ;

}

 

 

?>

 

 

Javascript:

 

<script type="text/javascript">

<!--

var i = 0;

function enable_submit(obj, domain)

{

var sb = document.getElementById("Submit");

var dom = document.getElementById('Domain' + domain);

if(obj.checked === true){

sb.disabled = false;

i++;

}

else{

 

if(i > 0){ i--; }

if(i == 0){ sb.disabled = true; }

}

}

function display_privacy(domain)

{

var sb = document.getElementById("Submit");

var privacy_label = document.getElementById('privacy_' + domain);

var privacy_cb = document.getElementById('Privacy' + domain);

var dom = document.getElementById('Domain' + domain);

 

if(dom.checked === true){ privacy_label.style.visibility = 'visible'; }

else{

privacy_cb.checked = false;

privacy_label.style.visibility = 'hidden';

if(i > 0){ i--; }

if(i == 0){ sb.disabled = true; }

}

}

//-->

</script>

 

Form Coding:

 

<table width="86%" border="0" align="center" cellpadding="6">

              <tr>

                <td align="center"><strong>Click "I Agree"  if you agree to the above terms.</strong><br />

                  <span class="copyright-txt">

                  <script>

var ip= '<!--#echo var="REMOTE_ADDR"-->';

document.write("Your IP Address of: "+ip+" is being recorded for security purposes.");</script>

                  </span></td>

              </tr>

              <tr>

                <td align="center"><form method="post" action="http://www.cssc-claims.com/webformmailer-terms.php" name="enableform"  id="Form1">

                    <label>Enter Your Name:

                      <input type="text" name="Name" id="Name" />

                    </label>

                      

                    <input type="checkbox" id="Domain1" name="Domain1" value="Agree" onclick="display_privacy(1)" />

                    I Agree

                    <label id="privacy_1" style="visibility:hidden;"><br />

                      <input type="checkbox" id="Privacy1" name="Privacy1" value="Verify" onclick="enable_submit(this, 1)" />

                      <strong>Verify</strong> &#8226; <span class="grey-body">When prompted enter "user" for user name and "password" for password</span></label>

                    <br />

                    <input type="hidden" name="ip_address" value="<?=$_SERVER['REMOTE_ADDR']?>" />

                    <input type="submit" name="Submit" id="Submit" value="Enter Portal" disabled="disabled" onclick="window.open('https://www.cssc-claims.com/sample-attorney/','mywindow')"/>

                  </form></td>

              </tr>

            </table>

 

Sorry for the long post but any help would be great. Thanks!

Also I need to remove this correct:

 

$logged_string = $_SERVER['REMOTE_ADDR'] . "|" . date("j M Y g:i a");

$file = fopen("userIP.log", "a");

fputs($file, $logged_string, strlen($logged_string));

fclose($file);

K tried that, just getting $ip in email from form. Can you tell me where I need to place the $ip line in the php script? Thanks.

 

Form email message:

Name: ip 23

Domain1: Agree

Privacy1: Verify

User_IP: $ip

Submit: Enter Portal

 

this is what I have now.

PHP

 

<?php

 

if ( !isset($_SERVER['SPI'])) {

        die();

}

 

if (!isset($_SERVER['DOCUMENT_ROOT'])) {

echo("CRITICAL: we seem to be running outside of the norm.\n");

header("Location: http://".$_SERVER["HTTP_HOST"]."/");

die("CRITICAL: Document root unavailable.\n");

}

 

$request_method = $_SERVER["REQUEST_METHOD"];

if($request_method == "GET") {

$query_vars = $_GET;

}

elseif ($request_method == "POST") {

$query_vars = $_POST;

}

reset($query_vars);

 

function customsort($a,$b) {

// $a is array for form vars, $b is comma seperated case sensitive field order

// this is case sensitive -- good idea to hrc that.

        $data = array();

        if ( strstr($b,',') == FALSE )  {

                $b = $b.",";

        }

        $ordering = split(',',$b);

        foreach ($ordering as $orderitem) {

                if ( ($orderitem != null) && ($orderitem != "") ) {

                        if (isset($a[$orderitem])) {

                                $data[$orderitem] = $a[$orderitem];

                        }

                }

        }

        foreach ($a as $key=>$val) {

                $data[$key] = $a[$key];

        }

        return $data;

}

 

function xmlentities($string) {

return str_replace ( array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $string);

}

 

$t = date("U");

$formhomedir = preg_replace('/.*\/home\/content/','',$_SERVER['DOCUMENT_ROOT']);

$formhomedir = explode('/',$formhomedir);

$formhome="/home/content".$formhomedir[0]."/".$formhomedir[1]."/".$formhomedir[2]."/".$formhomedir[3]."/".$formhomedir[4]."/data/";

 

$file_order = ".default";

$file_format = ".text";

$file_interval = ".15m";

$field_order = "";

 

if (isset($query_vars['form_order'])) {

if ($query_vars['form_order'] != "alpha") {

$field_order=$query_vars['form_order'];

$file_order=".custom";

$query_vars = customsort($query_vars,$field_order);

        $ip = $_SERVER['REMOTE_ADDR'];

}

else {

switch ($query_vars['form_order']) {

case "alpha":

uksort($query_vars,'strnatcasecmp');

$file_order=".alpha";

break;

default:

$file_order=".default";

break;

}

}

}

 

if (isset($query_vars['form_format'])) {

switch ($query_vars['form_format']) {

case "csv":

$file_format = ".csv";

break;

case "html":

$file_format = ".html";

break;

case "xml":

$file_format = ".xml";

break;

case "text":

case "default":

default:

$file_format = ".text";

break;

}

}

 

if (isset($query_vars['form_delivery'])) {

switch ($query_vars['form_delivery']) {

case "hourly":

$file_interval = ".60m";

break;

case "hourly_digest":

$file_interval = ".60mc";

break;

case "daily":

$file_interval = ".24h";

break;

case "daily_digest":

$file_interval = ".24hc";

break;

case "digest":

$file_interval = ".15mc";

break;

case "default":

default:

$file_interval = ".15m";

break;

}

}

$file = $formhome."form_".$t.$file_order.$file_format.$file_interval;

$fp = fopen($file,"w");

 

switch ($file_format) {

case ".csv":

$csvkeys = "";

$csvvals= "";

$firsttime = "";

while (list ($key, $val) = each ($query_vars)) {

if ( ($key == "form_order") ||

($key == "form_format") ||

($key == "form_delivery") ||

($key == "redirect") ) {

}

else {

if ($csvkeys != "") {

$firsttime=",";

}

$tmpkey=escapeshellcmd($key);

$csvkeys = $csvkeys.$firsttime."'".$tmpkey."'";

$tmpval=escapeshellcmd($val);

$csvvals = $csvvals.$firsttime."'".$tmpval."'";

}

}

fputs($fp,"$csvkeys\n");

fputs($fp,"$csvvals\n");

break;

case ".html":

fputs($fp,"<table border=\"1\" cellspacing=\"1\" cellpadding=\"2\">\n");

break;

case ".xml":

fputs($fp,"<form>\n");

break;

}

 

while (list ($key, $val) = each ($query_vars)) {

if ($key == "redirect") {

$landing_page = $val;

}

if ( ($key == "form_order") ||

($key == "form_format") ||

($key == "form_delivery") ||

($key == "redirect") ) {

 

}

else {

switch ($file_format) {

case ".html":

fputs($fp,"\t<tr>\n");

fputs($fp,"\t\t<td><b>$key</b></td>\n");

fputs($fp,"\t\t<td>$val</td>\n");

fputs($fp,"\t</tr>\n");

 

break;

case ".csv":

// content is already output

break;

case ".xml":

fputs($fp,"\t<field>\n");

fputs($fp,"\t\t<fieldname>".xmlentities($key)."</fieldname>\n");

fputs($fp,"\t\t<fieldvalue>".xmlentities($val)."</fieldvalue>\n");

fputs($fp,"\t</field>\n");

break;

case ".text":

default:

fputs($fp,$key.": ".$val."\n");

break;

}

}

}

 

switch ($file_format) {

case ".html":

fputs($fp,"</table>\n");

break;

case ".xml":

fputs($fp,"</form>\n");

break;

}

 

 

fclose($fp);

 

if ($landing_page != "") {

header("Location:  http://www.claimtrackerpro.com/aboutus.html" );

}

else {

header("Location:  http://www.claimtrackerpro.com/aboutus.html" ) ;

}

 

 

?>

 

 

Form:

<form method="post" action="http://www.cssc-claims.com/webformmailer-terms.php" name="enableform"  id="Form1">

                    <label>Enter Your Name:

                      <input type="text" name="Name" id="Name" />

                    </label>

                      

                    <input type="checkbox" id="Domain1" name="Domain1" value="Agree" onclick="display_privacy(1)" />

                    I Agree

                    <label id="privacy_1" style="visibility:hidden;"><br />

                      <input type="checkbox" id="Privacy1" name="Privacy1" value="Verify" onclick="enable_submit(this, 1)" />

                      <strong>Verify</strong> • <span class="grey-body">When prompted enter "user" for user name and "password" for password</span></label><br /><input type='hidden' name='User IP' value='$ip' />

                    <input type="submit" name="Submit" id="Submit" value="Enter Portal" disabled="disabled" onclick="window.open('http://www.claimtrackerpro.com/sample-attorney/','mywindow')"/>

                  </form>

i don't see your mail() function anywhere.

 

and please don't post ALL your code again, it's too much to handle.

 

but please explain very explicitly, what it is you're trying to do, ie: "i would like to have a form where when submitted, the information from that form is then emailed to a specified email account."

Went back to the drawing board and rewrote the php script, all working now  :D, thanks everyone for the help, learned from it. Below is the final WORKING php just in case anyone else may need it.

 

<?

$mailto='someone@yoururl.com';

$subject="Email Subject here Form";

$thankyou="http://www.yoururl.com";

$body = "Line here of copy\r\n";

$body .= "---------------------------------------------------------------\r\n";

$body .= "Name: ". $_POST['Name'] ."\r\n";; // Gets post value from select menu

$body .= "Agree: ". $_POST['value1'] ."\r\n";; // Gets post value from select menu

$body .= "Verify: ". $_POST['value2'] ."\r\n";; // Gets post value from select menu

$body .= "IP address: ". $_SERVER['REMOTE_ADDR'] ."\r\n";

$body .= "---------------------------------------------------------------\r\n";

     

mail($mailto,$subject,$body,"From: <noreply@yoururl.com>");

Header ("Location: $thankyou");

?>

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.