Solved

Ajax and PHP - Alternative to "echo"

Posted on 2014-03-12
2
852 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 110

Accepted Solution

by:
Ray Paseur earned 500 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 110

Expert Comment

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

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 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