Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ajax and PHP - Alternative to "echo"

Posted on 2014-03-12
2
Medium Priority
?
951 Views
Last Modified: 2014-03-12
Hi E's, when I use ajax and php, usually I use php "echo" to send the information to ajax, like this examples:
ajax.php
$(function(){
        $.ajax({
        type: "POST",
        url: "index.php",
        data: {"anything":anydata},
        success: function(dat){
                if(dat == ""){
                    alert("empty");
                } else {
                alert(dat);
                } 
        }
        });
});

Open in new window

index.php
<? echo "some data"; ?>

Open in new window

In this case the ajax call will return "some data", and that is correct.
The problem is when the malicious customer/client execute directly index.php, in this case will appear in the screen "some data". Off course this is a simple example with no value data, but this is just a example.
So my question is, have any alternative to the php "echo" to send data between php and ajax, that malicious client cant see when execute directly the php files?

The best regards, JC
0
Comment
Question by:Pedro Chagas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39924797
Basically the answer is "no," but you may be able to embed some kind of signal or indicator in the application.  For example, you can check $_SERVER['HTTP_REFERER'].  And you can check to see that the request method is POST.

The "problem" you describe is actually a useful debugging feature; it lets us debug the background script without having to use the jQuery script at the same time.  The isolation of functionality helps make for faster problem identification!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39924923
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question