My $link doesn't work in a href='mailto' - php

This is how i get my link
$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
And this is how it looks when i echo it echo 'My link : ' . $link;
http://www.mylink.com/myfile.php?int=&int1=ASD++
But when i put my link in
echo "<a href='mailto:$mail&subject=Aktiviteter&body=$link'>Press on the link</a>";
I only get
http://www.mylink.com/myfile.php
So i miss my ?int=&int1=ASD++ , how can i get it to? Sorry if im unclear.

Your link is being considered part of the string that builds the email.
Your email client is seeing the request as:
subject = Aktiviteter
body = http://www.mylink.com/myfile.php?int=
int1 = ASD++
Because the email client doesn't know what to do with "int1", it ignores it.
To get around this, you'll want to encode your $link variable into the mailto URL using PHP's urlencode function.
Try this:
<?php
$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$encoded = urlencode($link);
echo "<a href='mailto:$mail?subject=Aktiviteter&body=$encoded'>Press on the link</a>";
?>

echo "<a href='mailto:$mail?subject=Aktiviteter&body=$link'>Press on the link</a>";
after the email address you need to put ? not &
EDIT
this shold be the entire script, it works for me...
<?php
$mail = 'df#me.com';
$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo "<a href='mailto:$mail?subject=Aktiviteter&body=$link'>Press on the link</a>";
?>

Try string concatenation.
echo "<a href='mailto:" . $mail . "?subject=Aktiviteter&body=" . $link . "'>Press on the link</a>";

Related

How to trim my home url on the localhost

This is how I get my url on my localhost:
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
echo $url;
it returns : http://localhost/CodeSensei/menu because I am on the menu page.
How can I trim this? I only want "http://localhost/CodeSensei"
I know I can trim it like this
echo trim($url,"menu");
But the problem is, that "menu" is dynamic, it keep changing dependes on the page. Is there any way to trim my url so it will always and only print "http://localhost/CodeSensei" in any page?
There are many ways to achieve this. You can play around with different string manipulators like explode() etc.
Here is a solution using explode()
$variable = "http://localhost/CodeSensei/menu";
$variable = (explode("/",$variable));
$url='';
for($i=2;$i<count($variable)-1;$i++)
{
$url .= "/".$variable[$i];
}
$final_url = "http:/".$url;
echo $final_url;
Your output
http://localhost/CodeSensei
This function may help you. It get a url and return the url without after the last /.
<?php
function getSubUrl($originUrl) {
$url = parse_url($originUrl);
$url['scheme'] .= '://';
$url['path'] = dirname($url['path']);
return implode($url);
}
echo getSubUrl('http://localhost/CodeSensei/menu/123') . PHP_EOL;
// http://localhost/CodeSensei/menu
echo getSubUrl('http://localhost/CodeSensei/menu') . PHP_EOL;
// http://localhost/CodeSensei
echo getSubUrl('http://localhost/CodeSensei') . PHP_EOL;
// http://localhost/
echo getSubUrl('http://localhost/') . PHP_EOL;
// http://localhost/
echo getSubUrl('http://localhost') . PHP_EOL;
// http://localhost

php in header url error

I have just a quick question. i was using a normal html link tag to redirect to a paypal checkout page and it was working fine even when i had php inside the url. but when i was using it in a php header
the url cuts off where i enter the php.
header('location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=<? echo $product . " " . $server ?>&amount=<? echo $xprice1; ?>%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest');
You are placing the PHP code inside of the location redirect as a string. The code is not being evaluated as PHP.
Try this instead:
<?php
$url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=" . $product . " " . $server ."&amount=" . $xprice1 . "%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest";
header('location: ' . $url);
Or, you could keep it in one line like so:
<?php
header('location: ' . "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=" . $product . " " . $server ."&amount=" . $xprice1 . "%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest");
header('location: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXX&lc=UK&item_name=<? echo $product' . " " . '$server ?>&amount=<? echo $xprice1; ?>%2e00&currency_code=GBP&button_subtype=services&no_note=0&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHostedGuest');
This may solve your problem. Please dont forget to tick the answer right if it works.

defining POST variable as href link, target='blank'

I am trying to edit this code to make it a link which opens ins a new tab, but wherever I insert the "target='blank'" part in the code I get a parse error, can anyone one help me out please. Thanks.
$websiteurl = "" . $_POST['websiteurl'] . "";
need to add:
target='blank'
$websiteurl = '<a target="_blank" href="' .
$_POST['websiteurl'] . '">' . $_POST['websiteurl'] . '</a>';
You missed _.
put target="_blank"
Mine is like this:
$output .= "<p class='fb-page-name'><a href='". $app['link'] ."' title='". $app['name'] ."'>". $app['name'] ."</a></p>\n";
I had to use target='_blank' instead of target="_blank".
I'm just saying because maybe someone is struggling with it as I was.
$websiteurl = '' . $_POST['websiteurl'] . '';

PHP variable-infused link not writing to a variable?

http://www.reecemcmillin.com/albums/
<?php
$uncut = file_get_contents('http://www.google.com/#sclient=psy-ab&hl=en&safe=active&source=hp&q=' . $_POST['band'] . '+' . $_POST['album'] . '+zip+inurl:mediafire');
$strip1 = strstr($uncut, 'www.mediafire.com/?');
$link = substr($strip1, 0, 30);
echo $link;
?>
It doesn't seem to be writing the website content to $uncut. Can somebody help me figure out what's wrong? Thanks.<3
Clients are not supposed to send URI-fragments (the portion of the URI following #) to servers when they retrieve a document. PHP is probably sending a request for the google homepage, effectively: file_get_contents('http://www.google.com/');. If you echo $uncut, that's probably what you'll see you're getting back.
Try a querystring-based URI instead.
<?php
$uncut = file_get_contents('http://www.google.com/search?sclient=psy-ab&hl=en&safe=active&source=hp&q=' . urlencode($_POST['band']) . '+' . urlencode($_POST['album']) . '+zip+inurl:mediafire');

How to add a variable to this?

I am using the following snippet. How do I add q=$k in the <a href url>?
<?php
echo '<a id=d href="'.$_SERVER['PHP_SELF'].'?pg='.($s+10).'">Next</a>';
?>
<?php
echo '<a id=d href="'.$_SERVER['PHP_SELF'].'?pg='.($s+10).'&q='.$k.'">Next</a>';
?>
Something like that?
echo '<a id=d href="' . $_SERVER['PHP_SELF'] . '?pg=' . ($s+10) . '&q=' . $k . '">Next</a>';
You can do this:
echo "<a id='d' href='" . html_entities("$_SERVER[PHP_SELF]?pg="
. urlencode($s + 10) . "&q=" . urlencode($k)) . "'>Next</a>";
I added suitable escaping for the URL parameter and HTML output: URL encoding for the URL GET parameters, and HTML entity replacement for the entire URL string.

Categories