I need to find the user agent string, which it looks like UserAgentSTring.com does for me but I need to store that so I can pass it to the server side. I am not sure how to accomplish this?
The API docs say this:
You can send a ua string as post or get request (form field or in the query string).
Use 'uas' as parameter name:
?uas=Opera/9.70%20(Linux%20i686%20;%20U;%20en-us)%20Presto/2.2.0
this will automatically parse the string. To get some data you have to add one more parameter:
But if I put that line in my source code, in the header of my page how will the server side recognize it? Any assistance would be great.
If you are using PHP you can just use $_SERVER['HTTP_USER_AGENT'] but if that is not what you are looking for, look into HTML forms. Putting it in the header of your source code will do nothing for the server if it is not in PHP/ASP
Server-side approach with PHP:
<html>
<body>
Hi! You're using:
<?php
$jsonText = file_get_contents("http://useragentstring.com/?getJSON=all&uas=" + urlencode($_SERVER['HTTP_USER_AGENT']));
$obj = json_decode($jsonText, true);
echo $obj['agent_name'] . " " . $obj['agent_version'] . " on " . $obj['os_name'];
?>
Lol.
</body>
</html>
A client-side approach with Javascript is a bit more complex and you are better off not using useragentstring.com for this but using the browser's built-in mechanisms, like here.
Related
All Viewers I am New in Codeigniter, I need your guide to done my work, I want to Encrypted full URL like below example.
For example this is my url www.example.com & my controller is home, so full url is www.example.com/home
now I want to encrypted all controller, function like below
www.example.com/5115784bef2514430e7f74d9a71d4142a942efb0f7cc428626bda7633326f9d015fbacc60d93cd6b858f9b6e05c1e56263acb24297cecc720467eb4f222d81e5hdn5B
I can encrypted & decrypted the text well, but I just don't get how can I decrypted from url & make understand which controller or function its called, I want to decrypted everything after base_url.
please don't suggest me about using common controller, because I already know that & anyhow common controller its hide everything so its not required the encryption as I believe.
Waiting for your positive response, hopefully my problem will be solve soon. T.I.A
Well i never encrypt any URL before but you can use a php function url_encode
And "str_replace" function.
the reason for using "str_replace" beacause url_encode only encode special character in URL.
Hope I help some.
Try the code below.
urlencode(str_replace("your_domain.com/YourCOntrollerName/YourMethodName" , "SM5ah52" , yor_domain.com . "YourCOntrollerName/YourMethodName/YOuData"));
If not this. There is an library in CI Framework called Encryption.
You can get help from there Encryption.
Go with URI Routing and define one controller to decode whatever you are passing, and call proper controller / method from it.
You can use URI Routing with regular expressions.
$route["other_controllers/method"] = "other_controllers/method"; //you can add this kind of lines to not to affect other controllers
$route["([a-zA-Z0-9]+)"] = "home/decrypt/$1";
In the home controller, You can
Redirect to the page
Or
Load a view
public function decrypt($token){
//geting the page according to the token from database.
$desired_page = $this->some_model->get_page($token);
//if you want to redirect
redirect($desired_page);
//if you want to load a view
$this->load->view($desired_page);
}
I send invitation by mail to users with a encrypted email to know which user respond to invitation. Something like:
Hello, click on this link to start learning: https://example.org/start-learning?e=fwTreaN0WybffXdDfZZUNYB3FTFfZObCb7QFF5C4AFJvTjXabIPtRfcoXLkFYMUvD4FIZsmrDdEFN2OPKcTrAOSQLZfuKdfwcic1WtBxWSXWR1GEJD6we213A3BEPBpca0BxaaQ4GGMPFeRyXp6fPrG9WnTgWogwXUcnVtdwSEEdNHGuZsClTxR2AtD2JZN8VAEsRQKpFFShEDR2SET4KxGhLGM3M0FdDelrJtO8KXS2YRaddH==
The encrypted email is the long string above. I encode mail like this in a Mailable class:
$url = 'https://example.org/start-learning?e=' . encrypt($this->to[0]['address']);
Then this $url is added in a mail template like this:
<a href="{{$url}}>click me<a>
Then, when user clicks the link, it routes to a controller and the controller decrypts the payload:
decrypt($request->input('e'));
Then, it works for about 99% of people clicking link. But for about one percent, it does not work, I have an error decrypting. And I don't know why. This is the same Laravel application which encrypts and decrypts. Is there an reason for such a weird behavior?
Side note: I know decrypt always work and has not a random behavior (BTW I tested it on 10000 entries, it's OK). There must be something else with the mail process I don't understand.
I think you should use urlencode() when creating link so instead of:
$url = 'https://example.org/start-learning?e=' . encrypt($this->to[0]['address']);
you should use:
$url = 'https://example.org/start-learning?e=' . urlencode(encrypt($this->to[0]['address']));
to make sure it will be valid.
I am trying to send a get request through an MVC form but when I get the value in the controller using RequestParam somehow the HTML tags like <li> etc are getting filtered, any suggestion so as where these tags are getting filtered and any workarounds for them.
Thanks.
You can try using some URL Encoding like this %3Cli%3E%3C%2Fli%3E . If this is not working, you can try a hardcode encoding when sending and decoding when receiving. For example replace "<" with "|OPEN_BRACKET|" and ">" with "|CLOSE_BRACKET|" . Keep in mind, that this is a bad solution and use it as a last resort. Also make some checks for XSS attacks.
I'm having an issue where when I submit a form where the submit URL the just appends to the existing URL instead of replacing it.
It is supposed to be:
localhost/DataConnect/index.php/sites/MakeEdit/1
But instead I get:
localhost/DataConnect/index.php/sites/EditSite/localhost/DataConnect/index.php/sites/MakeEdit/1
I open the form with:
echo form_open('sites/MakeEdit/'.$site['ID'],$attributes,$hidden);
So I.m not real sure where I am going wrong. If there is any more information I can provide please let me know. Thanks in advance.
try:
echo form_open(base_url().'sites/MakeEdit/'.$site['ID'],$attributes,$hidden);
and don't forget to call the url helper on your controller:
$this->load->helper('url');
I have the following code:
<div><strong>Name: </strong><?php echo anchor('http://'.$link, $row->Name); ?></div>
Which takes a users input for a link ($link) and puts the url into an anchor tag. It, however, is not redirecting to the external link but simply amending the base url for the site with the stored URL. I attempted to add 'http://' to the beginning of the submitted link which works unless the user has already supplied http in the link input. Any advice on how to overcome this would be amazing.
Yes, per the documentation, anchor() creates links based on your site's URL.
If things are working as expected when URL's are prefixed with http://, but you're having trouble with users sometimes adding http:// and sometimes not, you could simply check the link to determine whether it's ok, or if you need to prefix it. Here's a basic example using strpos:
if(strpos($link, 'http') === FALSE){
// link needs a prefix...
$link = 'http://' . link;
} else {
// link is ok!
}
...use CodeIgniter's prep_url() function (thanks to #cchana for reminding me of it!):
This function will add http:// in the event that a scheme is missing from a URL. Pass the URL string to the function like this:
$url = "example.com";
$url = prep_url($url);