So thanks to the response to my previous question, I've tried to make a code to e-mail me if the code is on another site.
Here is my javascript which is intended for a potential code theif to take with them to their website:
<script type="text/javascript">
var mypostrequest=new ajaxRequest()
mypostrequest.onreadystatechange=function(){
if (mypostrequest.readyState==4){
if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
document.getElementById("result").innerHTML=mypostrequest.responseText
}
else{
alert("An error has occured making the request")
}
}
}
var url = document.domain;
var joel="www.joelhoskin.net76.net";
if (url!=joel)
{
mypostrequest.open("POST", "http://www.joelhoskin.net76.net/email.php", true)
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
mypostrequest.send(url)
}
</script>
and here is the php at joelhoskin.net76.net/email.php
`<?php
$url=$_POST['url'];
if(isset($url))
{
$to = 'FlexDevs#gmail.com';
$from = 'Errors#FlexDevs.com';
$subject = 'Stolen Page';
$content = $url."Site Stolen";
$result = mail($to,$subject,$content,'From: '.$from."\r\n");
die($result);
}
?>`
It isn't emailing me like it should
mypostrequest.send(url)
You do send data, but without key. Do it this way:
mypostrequest.send('url='+url)
It should make it work.
Related
I tried questions showing up before asking a question didnt have chance to make it work.
it works fine when I add it to mail send success alert, But I dont want to add script in php part.
I am trying to redirect contact page to an another page after form
success and delay a few seconds.
Here is my Jquery ajax :
$(document).ready(function(){
$('#ContactForm').submit(function(event){
event.preventDefault();
var formValues = $(this).serialize();
$.ajax({
url:"modules/contact.inc.php",
method:"POST",
data:formValues,
dataType:"JSON",
success:function(data){
if(data.error === 'ok'){
$('#result').html(data.error);
setTimeout(function() {
window.location = 'index.php';
}, 1000);
} else {
$('#result').html(data.error);
$('#ContactForm')[0].reset();
}
}
});
});
});
I tried the folowing setTimeout(); in success function but didnt work:
setTimeout(function() {
window.location.replace("index.php");
},1000);
Then I tried : window.location.replace("index.php"); without setTimeout function didnt work too.
window.location.href
window.location.hostname
window.location
This one works for modal in another page
setTimeout(function() {
window.location.reload();
}, 3000);
These are my tries didnt have a chance, Thanks for any advice and help.
EDIT: Here is php part for data.error contain:
$error = "";
// Validate user name
if(empty($_POST["fname"])){
$error .= "<p class='error'>İsim girmediniz.</p>";
} else {
$name = test_input($_POST["fname"]);
}
// Validate email address
if(empty($_POST["email"])){
$error .= "<p class='error'>E-Posta girmediniz.</p>";
} else{
$email = $_POST["email"];
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error .= "<p class='error'>E-Posta doğru formatta değil.</p>";
}
}
// Validate user subject
if(empty($_POST["subject"])){
$error .= "<p class='error'>Konu girmediniz.</p>";
} else {
$subject = test_input($_POST["subject"]);
}
// Validate user message
if(empty($_POST["message"])){
$error .= "<p class='error'>Mesaj girmediniz.</p>";
} else {
$message = test_input($_POST["message"]);
}
// Validate user departman
if(empty($_POST["departmant"])){
$error .= "<p class='error'>departman Seçin.</p>";
} else {
$departman = test_input($_POST["departmant"]);
}
if($error === ''){
require "../PHPMailer/mailer.php";
$mail = new mailSend();
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$name = test_input($_POST["fname"]);
$subject = test_input($_POST["subject"]);
$departman = test_input($_POST["departmant"]);
$message = test_input($_POST["message"]);
$error = $mail->sendMail($email,$name,$subject,$departman,$message);
}else{
$error .= "<p class='error'>Formda bir hata oluştu.</p>";
}
$data = array(
'error' => $error
);
echo json_encode($data);
EDIT : Got it work thanks for answers,
Displaying error causing the problem, $('#result').html(data.error); I changed it to text message instead of success message from php:
$('#result').html('Form successfuly');
$('#ContactForm')[0].reset();
setTimeout(function() {
window.location = 'index.php';
}, 1000);
it works fine.
String.replace() requires two parameters. As written, it will look for the string "index.php" and replace it with nothing. Try adding a regex to match everything and replace with your new URL.
setTimeout(function() {
window.location.replace( /.*/, "index.php");
},1000);
Use the full URL (i.e. https://yourdomain.com/index.php) or write a better regex. For instance, if your domain ends with .com, you could do something like:
setTimeout(function() {
window.location.replace( /\.com\/.*/, ".com/index.php");
},1000);
I am not able to send parameters to server file via ajax. i have checked comment.php with get parameters its working fine. But with ajax post parameter are not received by comment.php and else condition executes
Request Payload inside headers show url parameters received by server but when i echo $_POST array die(print_r($_REQUEST)); it gives me empty array
Here is the code i am using
<input type="text" name="comment" id="q_comment" placeholder="Add a comment" onKeyPress="postComment('q_comment')" autocomplete="off">
<script>
function $(id){
return document.getElementById(id);
}
document.onkeydown = function(event){
key_code = event.keyCode;
}
function postComment(comment_type){
if(key_code == 13){//If enter is pressed
if(comment_type == "q_comment"){//if comment added in question
var comment = $("q_comment").value;
}
else{//if comment added in answer
var comment = $("a_comment").value;
}
if(comment != ""){
var question_id = "<?php echo $id; ?>";//Returns current question id
//var params = "comment="+comment+"&question_id="+question_id;
var params = "question_id="+question_id+"&comment="+comment;//data to send to server
var ajax = new XMLHttpRequest();
ajax.open("POST","/ajax_call_files/comment.php",true);
ajax.setRequestHeader("Content-type","application/x-www-url-encoded");
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
var response = ajax.responseText;
console.log(response);
}
}
ajax.send(params);
console.log(params);
}
}
</script>
Comment.php
if(isset($_POST['comment']) && isset($_POST['question_id']) && !empty($_POST['comment']) && !empty($_POST['question_id'])){
require_once('../db_conn.php');
$user_id = $_SESSION['id'];
$comment = substr($_POST['comment'],0,530);
$comment = htmlspecialchars($comment);
$comment = mysqli_real_escape_string($conn,$comment);
$question_id = preg_replace('#[^0-9]#','',$_POST['question_id']);
$sql = "INSERT INTO comments(question_id,user_id,comment,date_time) VALUES('$question_id','$user_id','$comment',now())";
$query = mysqli_query($conn,$sql);
if($query){
echo mysqli_insert_id($conn);
}
else{
echo "Comment not added. Try again later";
}
}
else{
echo "no data recieved";
}
i have rewrite rule on file from which i am calling ajax. could it be the reason why url parameters are not received by the server
this is the rule i am using
RewriteRule ^questions/([0-9]+)/([a-zA-Z0-9_]+) questions.php?id=$1&title=$2 [NC,L]
Change the line.
ajax.setRequestHeader("Content-type","application/x-www-url-encoded");
to
ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
After
ajax.open("POST","/ajax_call_files/comment.php",true);
you need to add the url parameter as:
ajax.send(params);
After the above line of code when you are using the open() function, after you set the headers of the ajax call
At present you are trying to send the the url parameters to the server after ajax call
Basically, I have a script that is doing an infinite loop using file_get_contents, it's basically just running the function then incrementing the an $_GET variable which is passed to the file_get_contents url, the problem is obviously it's throwing an error for "Too many redirects", is their a way i can do it on Cron Job or a way of it doing it without error, here's my current code
$id = $_GET['id'];
$next_id = $id + 1;
$url = "http://www.website.com/profile/$id.json";
$json = file_get_contents($url);
$result = json_decode($json, true);
$headers = get_headers($url);
if($headers[0] !== "HTTP/1.1 404 Not Found") {
$query = mysql_query("query here");
if($query) {
echo '<script type="text/javascript">
<!-- window.location = "import.php?id='.$next_id.'" //-->
</script>';
} else {
echo '<script type="text/javascript">
<!-- window.location = "import.php?id='.$id.'" //-->
</script>';
}
}
Is there any other method or more efficient way of doing this ? I've tried using such method as sleep(5) before using my redirect but it still seems to keep doing it
Try adding a pause before the redirect in JavaScript:
echo '<script type="text/javascript">
<!-- window.setTimeout("window.location = \"import.php?id='.$next_id.'\"", 5000); //-->
</script>';
Hi i have this code this is xml with ajax i want the return value i get from res to not include an html tag because it always returns this value. For example i should return a value of 1 instead the ajax returns this value
<html>
</html>
1
this is my code for the xml
function sendEscalationEmail()
{
var xmlHttp = GetXmlHttpObject();
if (xmlHttp==null) { alert ("The system cannot process your request.\nPlease use browser that supports AJAX!"); return; }
var params1 = $('#formTrans').serialize();
var params2 = $('#formClient').serialize();
xmlHttp.onreadystatechange = function generateOutput()
{
if (xmlHttp.readyState==4 && xmlHttp.status==200)
{
var res = xmlHttp.responseText;
if (res.indexOf('1')<-1) alert('Transaction is saved but there has been an error sending the details to your supervisor\'s email.\nKindly contact the system administrator.');
else
{
alert('Transaction submitted and sent to your supervisor\'s email.');
document.getElementById('emailpreview').innerHTML = '';
$("#emailpreview").dialog("close");
}
}
};
xmlHttp.open('GET', 'send.esemail.php?'+params1+'&'+params2, true);
xmlHttp.send('');
}
here is the code for send.esemail.php
$arrTo[] = "xx#xx.com";
$mail = new htmlMimeMail();
$mail->setTextCharset('utf-8');
$mail->setHtmlCharset('utf-8');
$mail->setHeadCharset('utf-8');
$mail->setSMTPParams($SMTPServer, $SMTPPort);
$mail->setHtml($strHTML);
$mail->setFrom("xxxxx");
$mail->setSubject($strSubject);
$mail->setReturnPath('xx#xx,net');
$mail->setBcc("xx#eg.net");
$result = $mail->send($arrTo);
echo $result;
how could i remove the tags from the return the value so i can get rid of using indexOf to find the correct response. $result should be outputting only 1 but it has <html></html> 1.
In send.esemail.php
Write
echo strip_tags($result);
which should return only 1.
im using the below code in jquery, but my page itself reloading, i dont know where i have made a mistake.
var newstr = $.trim($('#umail').val());
newstr holds the email address
$.post("coding/unsub.php",{email:newstr},function(result){
$("#d_result").html(result);
});
i have
<span id="d_result"></span>
to show the result
my php code is
<?php
include ("../includes/dbcon_.php");
$unsub_sql = mysql_query("Delete FROM TblNewsLetter WHERE Email = '$_GET[email]'");
if (!$unsub_sql)
{
$ds_result = "<p style='font-size:200%;color:red;'>Some Error Occurred! Try Later.</p>";
}
else
{
$ds_result = "<p style='font-size:200%;color:green;'>Successfully Unsubscribed</p>";
}
mysql_close($con);
echo $ds_result;
?>
You said in a comment that you do the Ajax call from a form submit handler. You need to prevent the default submit behaviour, either by using the event object's .preventDefault() method or by returning false from the handler:
$("#yourFormSelectorHere").submit(function(e) {
var newstr = $.trim($('#umail').val());
$.post("coding/unsub.php",{email:newstr},function(result){
$("#d_result").html(result);
});
e.preventDefault();
// and/or
return false;
});
In your sql query
$mail = $_GET['email'];
$query = "DELETE FROM TblNewsLetter WHERE Email = $mail";
$_GET should be changed to $_POST
use like this
$unsub_sql = mysql_query("Delete FROM TblNewsLetter WHERE Email = '".$_POST['email']."'");