Check Browser PHP and put results in .txt [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I detect the browser with PHP or JavaScript?
I want to check what browser visitors to my site are using, and then save the results to a file named browser.txt on my server. Any ideas?
Thanks

Why not just install Google Analytics which does that (and an awful lot more) for you (albeit it doesn't store the data on your server)? Alternatively you could just check your server logs, the data should also be in there.

file_put_contents(
__DIR__ . '/browser.txt',
$_SERVER['HTTP_USER_AGENT'],
FILE_APPEND
);

In php you can do this:
get_browser( $_SERVER['HTTP_USER_AGENT']);
it will return an object/array containing all the information you need.
thake a look at PHP get_browser

Related

how to get the entire url in php including the # symbol with values [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
abcd.com/indexreadmore.php?#cat2
This is what the url in which I want to get all the parts like above mentioned, I can get a bit but not able to get the #cat2 and help me fetch entire url in php from the url bar.
The hashtags are not sent to the server, only the browser so PHP wouldn't be able to parse that from the address. You'd have to use javascript:
<script type="text/javascript">alert(window.location.hash);</script>
You cannot get the URL after the # in PHP..
The maximum you can attain is abcd.com/indexreadmore.php , To verify this you could just do a print_r($_SERVER); on your PHP code.
The content after the # can be retrieved only through JavaScript.
If you mean to parse the url, then there is parse_url function.
var_dump(parse_url('abcd.com/indexreadmore.php?#cat2'));
The browser does not send the hash fragment to the server if you mean get it in indexreadmore.php.

Is it possible to display the commands like 'top' on webpage using php? [duplicate]

This question already has answers here:
Why doesn't exec("top"); work on Linux?
(5 answers)
Closed 9 years ago.
Is it possible to display the commands like 'top' on webpage using php?
<?php
echo shell_exec('top');
?>
maybe this:
<?php
$output = null;
exec('top -n 1', $output);
var_dump($output);
?>
If I understand your question correctly, you're trying to get an interactive program showing on the client with live updates. This is not possible as you've demonstrated.
It seems you may not understand what's going on with PHP. PHP runs on the server before the page is downloaded by the client. The client then gets a 'snapshot' of the page as the server rendered it. Once the page is loaded on the user's machine, the server cannot touch the page.
To get interactive content, you have a few options (from least desirable and easiest to most desirable and most involved):
refresh the page
make periodic requests for updates (AJAX)
have the server push down changes (COMET, WebSockets)
Another problem is that interactive commands like top use a bunch of terminal-specific (refresh the terminal, rewrite bits of text, etc.) that will mess up the output in the browser. You'll need to do something like #David said and get a snapshot of the output and get that to the user periodically (choose one from above).
There are lots of libraries and tutorials for PHP available for whichever route you choose.

SetCookiePhp and GetCookie Javascript [duplicate]

This question already has answers here:
Javascript getCookie functions
(5 answers)
Closed 9 years ago.
Is it possible to set/get cookies between php and javascript?
I tried two cases:
setCookie on Javascript, and then getCookie on PHP, it works
setCookie on PHP, and getCookie on Javascript, then it failed, always return null.
I am wondering if it is supposed to work in this way?
I think the issue was, my php folder is under a different directory apart from html page.
I went through the php documentation about cookies, and found out that Cookies can be saved for specific page which is depending on the path you specified.
What I did changed right now is specify the path as '/', so the cookie will be available for all pages:
setcookie($GLOBAL_COOKIE_KEY_CREATED_CV_THEME_ID, $param_themeId, time()+$GLOBAL_COOKIE_EXPIREDAYS, '/');
Ref: http://us.php.net/setcookie
Hope this could help, but if someone found it's wrong, please comment, thanks.

Creating a screenshot image of a website if given nothing other than a url? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Website screenshots using PHP
I was wondering if it is possible to create a screen-shot-like preview of a website if given nothing other than a url?
Yes, you can, please read the following stackoverflow questions:
generating-a-screenshot-of-a-website-using-jquery
website-screenshots-using-php
There are some tools with the goal of snapshotting the website to an image, so, using Jquery in conjunction with PHP you can achieve your goal!
Using only JavaScript/jQuery? Likely not, as that would violate the same origin policy. And even if you could, it's be challenging in JavaScript to make it into an image.
You can use a service like BitPixels as well. Use JSONP if there are any same origin issues and it should be easy enough.

Test Connection to YouTube Servers with JavaScript or PHP [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Detecting if youtube is blocked by company / ISP
Is there a way to test if a user's browser has access to YouTube servers using JavaScript or PHP?
Some companies block access to certain sites, like YouTube for obvious reasons, and therefore it's necessary to stream fallback videos from a different CDN if that is the case. I currently have a solution using ActionScript, but I would prefer to use PHP or JavaScript to replace the div instead if that's possible.
EDIT:
As #NathanKleyn said the php code below wil only check if your server has access to youtube, not the client that's using your tool. If this is what you want (which i guess it is after re-reading your question) the javascript solution below should be a solution too.
var request = new XMLHttpRequest();
request.open('GET', 'http://www.youtube.com', false);
request.send(null);
alert(request.status);
One way to achieve this is to request the headers on youtube.com with PHP's get_headers(), check if the HTTP code returned to determine if the site is accessible.
You could probably do this with curl too though it is more complex, yet alot faster.

Categories