How to see what URL my PHP executed on - php

I am not asking about regular "execute php on my domain and get URL" but this:
I display image from php, here: http://myservice.com/ShowImage.php?Id=10
So Bobby who runs a website BobbyBlog.net could use this image on his blog like:
<img src=http://myservice.com/ShowImage.php?Id=10>
I want to know that Bobby has loaded image on his website, so what I need to intercept in my ShowImage.php script would be "BobbyBlog.net" string. I am afraid this is not possible with PHP as image request is separated from Bobby blog. What do you think?

As far as I know there is not way to capture which site executed your script, like you ask for. The server variable $_SERVER['HTTP_REFERER'] sets the referring page (the page that referred to yours) but I don't think that will have any values in this case. If I am not mistaken, this is the case for most programming languages, as this depends on the web server level, not the programming language. This means that you can not simply use Python or Perl and expect it to work.
Edit: On web server level this should be possible. Linking to images from other sites is commonly referred to as hotlinking. There are several guides on how you can disable this. Here is one for Apache.
Edit2: Looking deeper at the problem it may seem like you can inspect the $_SERVER['HTTP_REFERER'] value. This is described in this related SO question. It also mentions that this is not possible if sent over HTTPS, and that the value can be spoofed. In those cases there is no way of knowing the origin. Hope it helps.

Related

Meaning of php , when parsing a json

I have seen that after url for example
Please help me tu understand this, i have tried to find somewhere else but nothing
What does" php?later_word=" mean, and how to do that
So, you wan't to do the same as you said in the comment section on your first post.
So here a short resume how you can use GET paremter. Lets say, you have a index.html file. Create a link in it, for example:
Click here
So, in your filename.php you can do:
<?php
$yourvalue = $_GET["key"];
?>
So, this means you can acces this key from the url with $_GET. In this example, $yourvalue would contain "AnythingYouWant". So if you would do the following:
<?php
$yourvalue = $_GET["key"];
echo "Here is your $yourvalue";
?>
The output would be:
Here is your AnythingYouWant.
This is useful because PHP variables are not saved when you click on a link for example.
But dude, we posted you a link to the official description... normally you would find this answer by yourself. I really recommend you to read more tutorials, this are the basics of basics.
I know this can seem overwhelming, so I'll give you some pointers on which parts of internet basics you seem to be unclear about:
URLs. Find out what a URL is, what it is made of (scheme, path/suffix, domain name, query, port, and also the optional username/password in URLs might be good things to know about).
HTTP requests and in particular HTTP "methods". The most common you need to know are GET and POST, but there are many others, and you should have a basic understanding so you know how to look up a new one.
Web servers (i.e. HTTP servers, which at their most basic show static files of a web page). Usually people use Apache or NGinx as servers
Scripting languages to run scripts when someone sends a request to a web server. Examples are Python, Ruby, Perl and, in your case, PHP.
All of these work together to present a modern web site that shows more than just static text and pictures. #1 in that list is something you already need to know as an advanced user of any web browser, understanding 2 and 3 kind of goes hand-in-hand with making even simple web sites of your own, and once you understand that, you can advance to one of the languages mentioned in #4 to make a web site that can do something with user input.

Methods of injecting text

I recently created an image that automatically changes depending on the time thanks to a PHP script. I'm now thinking about doing something but I'm not sure if it's possible.
I do have restrictions. I need this to work on a forum board so it means I have to have all scripting on a different server. I would Google how to do this but I'm not sure what to search hence the broad title. If someone could possibly tell me if it's possible and show a small example to get me on the right track, that'd be appreciated.
What I need to do is print text out onto the page. As I stated above, all the scripting needs to be on a different server as the forum doesn't allow for php and only basic HTML (similar to here). This means I can't use include 'file.php';.
IMHO You have two options
Use HTML iframe element to embeed the external content (just give the external URL and the browser will handle the rest)
Call ajax request from javascript and inject the result into the DOM tree of the board.
Now that Your decision what suits You more.

PHP - Getting information from link itself rather than GET parameters?

Consider a situation of a URL as:
www.example.com/softwares/download.php?f=firefox&v=13
It does not look as good as URL:
www.example.com/softwares/firefox/download?v=13
or same download.php used as:
www.example.com/softwares/chrome/download?v=20
How can I achieve this type of URL filtering in PHP?
Some point I want to covered here:
I don't need a folder-hierarchy here like having different folders for /firefox/ and different for /chrome/
There could be only two PHP files (as I wish to) for all products: /software/software-info.php and /software/download.php (already got here).
I am able to put and fetch information from database in PHP but just want to have different link for different product.
I am a Java Web Developer in which you have Filters to get information from a part of link and redirect the request accordingly.
I am new in PHP programming and if this question is already asked or obvious than please pardon me and provide that question link.
This is ideally what you should use url rewriting (mod-rewrite in .htaccess) for.
Your visitor navigates to:
www.example.com/softwares/firefox/download?v=13
or even
www.example.com/softwares/firefox/13/
but your server will understand it as:
www.example.com/softwares/download.php?f=firefox&v=13
You can use htaccess files to do URL rewriting. Essentially this would allow you to take the segments of the url after /software/ and pass them ass parameters to be controlled by the software script.
There are also a bunch of PHP frameworks which use 'routes'. They're based on a similar principal as URL rewriting. I'd recommend Codeigniter as a good starting point - it's a straightforward framework, which plenty of documentation and tutorials.
Good luck!

What "version" of a php page would crawlers see?

I am considering building a website using php to deliver different html depending on browser and version. A question that came to mind was, which version would crawlers see? What would happen if the content was made different for each version, how would this be indexed?
The crawlers see the page you show them.
See this answer for info on how Googlebot identifies itself as. Also remember that if you show different content to the bot than what the users see, your page might be excluded from Google's search results.
As a sidenote, in most cases it's really not necessary to build separate HTML for different browsers, so it might be best to rethink that strategy altogether which will solve the search engine indexing issue as well.
The crawlers would see the page that you have specified for them to see via your user-agent handling.
Your idea seems to suggest trying to trick the indexer somehow, don't do that.
You'd use the User-Agent HTTP Header, which is often sent by the browsers, to identify the browsers/versions that interest you, and send a content that would be different in some cases.
So, the crawlers would receive the content you'd send for their specific User-Agent string -- or, if you don't code a specific case for those, your default content.
Still, note that Google doesn't really appreciate if you send it content that is not the same as what real users get (and if a someone using a given browser sends a link to some friend, who doesn't see the same thing as he's using another browser, this will not feel "right").
Basically : sending content that differs on the browser is not really a good practice ; and should in most/all cases be avoided
That depends on what content you'll serve to bots. Crawlers usually identify themselves as some bot or other in the user agent header, not as a regular browser. Whatever you serve these clients is what they'll index.
The crawler obviously only sees the version your server hands to it.
If you create a designated version for the search engine, this version would be indexed (and eventually makes you banned from the index).
If you have a version for the default/undetected browser - this one.
If you have no default version - nothing would be indexed.
Sincerely yours, colonel Obvious.
PS. Assuming you are talking of contents, not markup. Search engines do not index markup.

how do you take a snapshot of your current browser window using php

I've tried searching everywhere but there's seems to be no implementation available other than having the client use a file (batch/exe of some sort).
You just can't do it. PHP is server side scripting language, maybe you can do that using JavaScript, but I'm not even sure about that.
I know someone implemented such service, but actually he had to use Mozilla browser, which opened, a script (I think it was not JS, maybe perl, c/c++) made a screenshot and uploaded it.
I'm assuming you mean "your" in the general sense. If you mean "how does one take a screenshot...", you generally hit the print screen key. If you're trying to capture your users' browser output, I'd say that it's probably not possible. If it were, the best you could get is the output of what you wrote yourself.
Google Gears might be hackable to do something close, if you can simulate the print screen key press with JS and get the file to save somewhere gears can access.
You can't do that in PHP, as PHP is running on the server, and not the client.
To get screenshots of the browser, you can take a look at, for instance, this list.
If you are look for an automated solution to take screenshot of web pages opened in a browser window, you could also look at this question : How to capture x screen using PHP, shell_exe and scrot and it's answers.
And, finally, and without selecting any particular post, you can try a search on SO ; something like screenshot browser, sorted by relevance, seems to get some interesting posts :-)
Good luck !

Categories