I need to pass a single variable in a querystring from one application (in PHP) to another (in ASP.NET). It's a one way transfer...That is I need to encrypt it in PHP and decrypt it in ASP.NET (c#).
I'm barely a newbie on PHP and I'd like not to have to do more than add a tag to the page that needs to do the passing.
The data will be anywhere from 5 - 15 characters..only letters and numbers.
Thanks!
How about something like this?
<?
$query_string = base64_encode($_SERVER["QUERY_STRING"]);
header("location: http://www.domain.com/page.aspx?query_string=$query_string");
//rest of php code...
?>
Then in page.aspx you decode that query string
Related
I'm a little unsure of how to word this one but essentially, I want to achieve the following:
http://my.website/?url=http://another.website/?var1=data&var2=moredata&id=119
And for the URL variable to be: http://another.website/?var1=data&var2=moredata&id=119
Naturally, PHP sees var2 and id as new variables. This would be used to pass a full URL from one page to another, however, it poses an issue when the page already has its own variables in the URL!
Any help appreciated!
You need to encode the secondary url which you're putting inside the url variable when you create it. This will ensure it doesn't contain special querystring characters that the receiving website will misunderstand. If the code in my.website is PHP too then the urlencode function (http://php.net/manual/en/function.urlencode.php) is your friend. For example:
urlencode("http://another.website/?var1=data&var2=moredata&id=119")
produces
http%3A%2F%2Fanother.website%2F%3Fvar1%3Ddata%26var2%3Dmoredata%26id%3D119
which will not be misunderstood by the PHP code reading it as containing further separate variables.
I would like to pass the value of a php variable using the URL, by using the variable name. Here is a sample of what I am trying to achieve, it doesn't work, bu also doesn't crash so I know that I am close....anyone...please:
Unit Learning
Personally I don't like to put little pieces of PHP code inside HTML. It can be done, but it is problematic. Better to write clean PHP code, like:
<?php
$url = 'student_what_learning_unit.php?student='.urlencode($student_user);
echo 'Unit Learning';
You do need the urlencode() for an URL, see:
http://php.net/manual/en/function.urlencode.php
Just add an echo like this:
Unit Learning
Ho you all, I've got a script in a Wordpress post that sends the value of 4 variable to a URL.
The fact is that since natively WordPress converts & to &, the URL that is meant to recive those variable cannot get them, since the final URL will be
http://localhost/php/add.php?a=VALUE1&b=VALUE2&c=VALUE3&d=VALUE4
instead of http://localhost/php/add.php?a=VALUE1&b=VALUE2&c=VALUE3&d=VALUE4
Now I know that it is possible to fix this problem by commenting to lines in wp-includes/formatting.php, but I'm looking for a PHP function that can convert the URL with '&' to an URL with just '&'.
Is it possible? Thanks!
You will need to use htmlspecialchars_decode(). Consider this example:
$url = 'http://localhost/php/add.php?a=VALUE1&b=VALUE2&c=VALUE3&d=VALUE4';
$url = htmlspecialchars_decode($url);
echo $url;
// http://localhost/php/add.php?a=VALUE1&b=VALUE2&c=VALUE3&d=VALUE4
I have a URL dynamically displayed with a PHP script. This URL comes to be the name of a CSS class. I need to use this class name into a jQuery script after an Ajax call response (All the HTML into this specific class has to be hidden).
The URL contains / and . and : — To make it easier in my jQuery script, I would like to convert the URL into an Integer with a PHP function (like hash("md5",)) ... and in my JavaScript, convert the URL again into an integer that will be obviously the same.
I read that How to calculate md5 hash of a file using javascript
but it doesn't look like the best solution. Does anyone have a more intelligent solution?
Regards
You are probably looking for encoding and not hashing, as you want to read the URL back. I'd try using base64 - on the server side: http://php.net/manual/en/function.base64-decode.php and http://php.net/manual/en/function.base64-encode.php
And on client (JavaScript) side: http://www.webtoolkit.info/javascript-base64.html, How can you encode a string to Base64 in JavaScript?
i have script
<?php
$to = $_GET["to"];
header("Location: $to");
?>
if i call script such
out.php?to=http://site.ru/page.php?param1=1¶m2=2
in param $to be only http://site.ru/page.php?param1=1&
how to fix? i want that $to = http://site.ru/page.php?param1=1¶m2=2
You can escape the URL at the site calling out.php:
Go to $to
& is a reserved character in an URI. When you access this URL, ¶m2=2
is interpreted as belonging to the current URL and not to the value of to.
If you want to transmit it literally, you have to encode it with %26:
http://site.ru/page.php?param1=1%26param2=2
Most programming languages provide a function to do so. (e.g. JavaScript, PHP). The best thing is to encode the whole URL.
$to must be urlencoded, but note that you giving a redirect script to anyone, so, any phisher can use it.
So, it would be better to store urls in the database and pass only an identifier.
try encoding the to URL in base64 and then in the example that u have shown decode it before you pass it to the header :)
urlencode it
urlencode($to)
I ran into the same problem before, this is what I did:
$arr=explode('?to=',$_SERVER['REQUEST_URI'],2);
$new_to=$arr[1];
Now you can use the $new_to variable.
Of course if you're using this for production environment, I would recommend encoding the url as the other answers advised. I was using it for testing curl script. getting the variable this way has lots of flaws, so be careful.
You can use a Function called "html_entity_decode"
Click Here for more information about this function
or use md5 function to encrypt the URL and then decrypt it when you put it into a varriable.
I hope this can help you