PHP variable in href in PHP - php

I'm struggling with the syntax of this:
echo '<strong>Datasheet</strong>';
The central PHP element gets a URL from a WooCommerce custom field (I know this works ok on its own). That needs to be turned into a viable link opening a new page, and the whole sits in a PHP wrapper on the page.
Where am I going wrong?

Try this hopefully, it will work.
echo '<strong>Datasheet</strong>';

Try adding more to / changing the href
something like this might work
echo '<strong>Datasheet</strong>';
You'll have to adjust a little bit, but should do the trick

Related

file_get_contents not returning entire webpage

I've been trying to retrieve the contents of a webpage (http://3sk.tv) using file_get_contents. Unfortunately, the resulting output is missing many elements (images, formating, styling, etc...), and just basically looks nothing like the original page I'm trying to retrieve.
This has never happened before with any other URLs I have tried retrieve using this same method, but for some reason, this particular URL (http://3sk.tv) refuses to work properly.
The code I'm using is:
<?php
$homepage = file_get_contents('http://3sk.tv');
echo $homepage;
?>
Am I missing anything? All suggestions on how to get this working properly would be greatly appreciated. Thank you all for your time and consideration.
Thats normal behaviour, as you are only grabbing the file, and not related images, stylesheets etc...
I have one quick workaround to fix relative paths
http://www.w3schools.com/tags/tag_base.asp
Just add to your code <base> tag.
<?php
$homepage = file_get_contents('http://3sk.tv');
echo str_replace(
'<head>',
'<head><base href="http://3sk.tv" target="_blank">',
$homepage
);
?>
It's should help.
This is to be expected. If you look at the source code, you'll notice many places which do not have a full URL (ex lib/dropdown/dropdown.css). This tells the browser to assume http://3sk.tv/lib/dropdown/dropdown.css. However, on your website, it will be YOURURL.COM/lib/dropdown/dropdown.css, which does not exist. This will be the case for much of the content.
So, you can't just print another website's source and expect it to work. It needs to be the same URL.
The best way to embed another website is usually to just use an iframe or some alternative.
The webpage is not completely generated server-side, but it relies heavily on JavaScript after the HTML part loads. If you are looking for rendering the page as it looks in browser, you may need a headless browser instead - see e.g. this binding to PhantomJS: http://jonnnnyw.github.io/php-phantomjs/

captcha in smarty doesn't work

I have this problem with smarty, I tried to add a captcha in smarty but I can't see the way of make it work, basically the error comes when i try to show the captcha image, in a normal php file I could embed this php script:
<?php
$SampleCaptcha = new Captcha("SampleCaptcha");
$SampleCaptcha->UserInputID = "CaptchaCode";
echo $SampleCaptcha->Html();
?>
But for smarty I did this:
$SampleCaptcha = new Captcha("SampleCaptcha");
$SampleCaptcha->UserInputID = "CaptchaCode";
$captcha=$SampleCaptcha->Html();
$sy->assign('captcha', $captcha);
The think is that the variable captcha does print the whole html to show the captcha but when it prints the image attr src it does it in php still.
<img alt="CAPTCHA" src="botdetect.php?get=image&c=samplecaptcha&t=da491a96235a0d9f5fbeb0d7c0accc89" id="SampleCaptcha_CaptchaImage" class="LBD_CaptchaImage">
I tried to use a smarty plugin function but it does the same.
Any expert in smarty may know the answer.
Many thanks.
Try this.
It may help you as this site has good examples across different platforms.

Trying php to reload page

I am trying to use an image as a button to refresh pages on a website. The footer (a php include) is currently using this code to refresh each page:
<img src="/images/refresh.png">
which of course works. BUT I would like to improve it. Essentially, it would be something like this:
onClick="javascript: window.location.href='abcd.html';"
BUT I need it to work dynamically because I'm using php pages. So I was thinking this would work:
<img src="/images/refresh.png">
But it doesn't work. Any ideas? I'm using <? php $_SERVER['REQUEST_URI'] ?> wrong (obviously), so, any ideas for assistance? Thank you for any help!
Problem noticed is you have a space between <? and php in the following line:
<img src="/images/refresh.png">
Also you want to echo out the value for $_SERVER['REQUEST_URI']. You are just calling $_SERVER['REQUEST_URI']. Also as #NickCoons pointed out when using the echo construct you need to add a semi-colon i.e. echo $_SERVER['REQUEST_URI'];.
Try the following:
<img src="/images/refresh.png">

Can I modify anchor tag href in htaccess?

Not sure if this is possible but wanted to know if htaccess has a trick...
Say I have anchor tag href like this -
Click here
I have changed the URL structure using mod_rewrite but wanted to know if i can hide the actual URL in href using htaccess.
i.e when a user hover over the anchor tag, the browser displays http://example.com/index.php?id=12345 at the bottom. All I want the browser to display is http://example.com/index/12345 without changing it manually on all my pages.
Thanks for the help !
Why don't you change the link to the following?
Click here
As you can change the .htaccess I expect that you own or adminstrate this domain. So it should be possible.
If the links are generated by PHP code, then I suggest you to implement and use a translation function like:
function beautify($ugly) {
// your logic comes here
return $nice; // ;)
}
... and wrap it around the existing code that currently outputs the urls. This would have two advantages:
It's easy and more failsafe to migrate to the new url scheme
From now on you have control over all url related code using a single function
I agree, htaccess can't help you. I guess you'll have to change them manually.
I wish I could be of more help
No. htaccess is for processing input to the web server, not data sent back from the server.
If you use jQuery you could have it rewrite the href when the page loads using something like this.
$(function(){
$("a").each(function() {
this.href = 'some_new_url that you made based on the one in this.href';
});
});

WordPress URL with anchor tag resolving to 404

I have a bizarre issue with WordPress wherein I have an anchor tag on my about page like this:
<h2><a id="comments">Why No Comments?</a></h2>
and when I link to it in my footer like this:
Why no comments?
it inexplicably resolves to http://www.everydaytype.com/omments.
What could be going on here?
Note: The same thing happens when I navigate to the URL of the anchor tag manually.
(Reference: everydaytype.com)
UPDATE: I have disabled all of my plug-ins (I have one that manipulates a link in my header), and this is still occurring.
It's a pretty bizarre thing for a site to do.
If you load the url http://www.everydaytype.com/about/#comments into a View Source window in your browser, you'll find that it contains the following code:
<script>if(window.location.hash) {
var hash = window.location.hash;
var hashtourl = hash.substring(2)
window.location.href = "/"+hashtourl;
}</script>
This code does exactly what you're describing.
I have no idea why it would do that, but that's what it's doing.
My guess is that it's expecting a #! rather than just a #, hence the dropping of the first two characters rather than just the first, but that's just a guess. And if that is what it's expecting, it really ought to be checking for it rather than making an assumption.
I guess it must be part of some plugin that you don't know about or thought you'd disabled haven't fully, or something. Either way, having the code above to hand should help you locate it.
That's all I can do to help, but I hope it gets you in the right direction.

Categories