How does include() work? - php

I was looking at some topics that is talking about my question but couldn't find or understand my specifics.
I have users, I want redirect that user to a website outside my web, stay there for 10 seconds, and then click a button that confirms that he has waited those seconds. I was thinking doing that like this :
<div id="shown_box_at_top"> you have to wait <div id="timer">10</div> more seconds. </div>
<div id="shown_box_after_timer"> Please click here</div>
<?php include('www.wesite.com');?>
Of course it's just an example but if I do it this way, and www.website.com have a visitor counter, the counter will add him as a visitor or not? Or maybe there is a better way to do it?

If you want to redirect the user to this external website, you can use PHP header function to do something like this :
header('Location: http://www.example.com/');
However, once the user clicks on this link, you will lose control over that user as he won't be on your website anymore. I think the better way to do this would be to use iframes to display the external website on your own webpage. The user will increment the external page's visitor counter and since the user will be on your web-page, you will still have control over this user to do what you want after (let's say) 10 seconds using jQuery.

First of all, include executes the HTML as php code locally, which is definitely not what you want, as it would create a security vulnerability. Instead, if at all, you want file_get_contents. Even better, consider using an iframe so that the website gets downloaded from the client.

Related

How do I find out that a link was seen

I'm trying to make a page with some links and when somebody clicks on a link, the score count will go up.
How can I find out the visitor who has really seen the page related to link? But not just click the link and close the page for score...
really seen means: page loads completed.
and my links opens in new window.
any solution?
You cant really see pages that aren't in the same domain. Chrome even puts them in a separate thread.
Back in the day you could have used a CSS exploit talked about here: https://developer.mozilla.org/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector
If you really want to make a page with this kind of functionality you will have to make a browser plugin/extension.
You can include a nonce token in the link, and post that token to the server, render the page embedding that same token in some javascript and have the javascript post back the token when the page is done rendering. Seems kinda overkill though.
The only thing I could thing of is maybe make the link to like a redirect page on your site and then you could control to see if the page was loaded and then like after the page was loaded redirect to the actual webpage to link is intended. This way you know for sure that the user waited to view the webpage.
Other than that I don't think there is any other way for you to go about this.

Javascript setInterval function

I have a page where it shows users posts and refreshes automatically using the jQuery setInterval function.
$(document).ready(function(){
setInterval(function() {
$('#content').load('test.php');
}, 5000);
});
But the problem is I am going to have to create a duplicate page called test.php containing the same content which will be called every 5 seconds. I don't want people just viewing the source and finding the page with all the data on.
For example this site has a recent forum topics page which updates every couple of seconds,
http://awesomescreenshot.com/0d4o0n2e0
I look in the page source and find the link to the page and this is what I find
http://awesomescreenshot.com/0a2o0n691
I don't want people to be able to find that...
Is there a better way round this jQuery function? E.g. calling a php function to just run the query which will be in the test.php file?
Thinking about security by thinking where the data is going isn't quite right. Instead think about who has access to it. If you don't serve that data from the PHP to someone who shouldn't see it in the first place, then it doesn't really matter how they view it.
So your test.php needs to have security around it that hooks into your authentication. In psuedocode:
if (current user is authorized)
send data
else
403 Access Forbidden
Security through obscurity will only hurt you in the long run. Even if you could obscure the location of that data, it leaves open the possibility that someone may find it eventually. So do the security on the backend, out of reach of hackers, instead.

PHP - Open 2 Html Pages

I have this problem to solve.
I gonna make an email campaign to my clients with some affiliate promotions.
The email will have some direct links to the promotions that goes through a php script in my site. (ex: http://mysite.com/promo.php?promoId=x)
In this script I will manage my database queries and cookie.
In cases that I detect through the cookie that this user has not made any click in the last x days I would like to present him with two html pages: my main website page and the external site referring to the promo.
How can I do this? I currently use header( "Location: $promo_url" ) to redirect to the promo url... but in same cases stated before I would need two urls to open.
Thanks in advance for all your answers
GS
You can either use frames (ugh), an iframe within the main page to display the second page (somewhat less ugh), or use popup windows (truly ugh, and probably not possible due to everyone having popup blockers these days).
You could have the script output JavaScript with window.open instead.
<script type="text/javascript">
window.open("link1"); // open link1 in a separate window
window.location.href = "link2"; // point this window to link2
</script>
If you can, however, it would be much better to explicitly show the user a link to the second location somewhere on the page instead of forcefully opening another window / tab for them.
Show them your site, and in your site have a hidden a link tag, which will link to the affiliate site with the attribute _blank. Using jQuery, once the DOM is ready trigger a click event to the hidden link tag.
E.x.
HTML
<a id="affiliateLink" href="http://www.affiliatesite.com/asdad" target="_blank" style="display:none;">Visit Affiliate</a>
JavaScript
$(document).ready(function(){
$('#affiliateLink').trigger('click');
});
There's really no good way to do what you want without using iframes (ugh) or popups (double ugh). The other answers are how to use those techniques, but a possible 'better' solution would be to display a banner on your page when you detect the user hasn't been to your site in a while. The banner could say something along the lines of Click here for information about our awesome promotion, and it'd be easy to make it stand out. That way, you're not forcing popups (which no one will ever see), and while iframes aren't terrible from a user perspective, they don't really scream "modern web design".

How can I place a photo on someone else's webpage when linked to from my site?

I know this is a strange thing to want to do, but...
How can I place a photo at the top of someone else's webpage ("Page B") -only- when a visitor links there from my page ("Page A")? I have permission to do this, but with certain limitations: my code needs to be in one location on Page B, and I can't make major changes to Page B. I cannot use Page B's server to run PHP, but I can run PHP on Page A's server.
The photo needs to open automatically with the rest of the Page B, and not require any user input to show up.
This is a unique vendor/retailer situation, so unfortunately I can't provide the urls.
Thanks for any help.
In PHP, you'd do something like:
<?php
if($_SERVER['HTTP_REFERER'] == 'http://www.yoursite.com/referringpage.html')
{
printf('<img src="yourbutton.png">');
}
?>
Which is very limited because:
It will only work for a referring single page (referringpage.html) and not otherreferringpage.html
It will only work for a single landing page. If the user navigates off of the page, then back (not through browser's back), the button will not show up.
To solve the first you could do a substring of the referrer, e.g.
<?php
if(substring($_SERVER['HTTP_REFERER'],0,24) == 'http://www.yoursite.com/')
{
printf('<img src="yourbutton.png">');
}
?>
To solve the second you could set session variables (except then you'd need access to the very top of the "outermost" page -- which doesn't sound like an option.)
Depends on the design of the page.
Lets say,
If the page is divided into frames, then you can use iframe.
if It's a single page, try have a separation with div tag. Insert the html into Div Tag.
If the above two points won't help you,give an idea of how the page is designed
I think a simple answer would be to write a html page (lets call it linkPage) that has the image/text/div or whatever you want to display on the top and then include an iframe that would cover the rest of the page using css. You could pass the page you are linking to as a GET or POST parameter to the linkPage and then set the src of the iframe to that url.
There are probably other ways of doing this that are more complicated / seamless but this would be the easiest, quickest way to get it done.

I'm not sure if I should use a redirect

I have an affiliate link on my webpage. When you click on the link it follows the href value which is as follows:
www.site_name.com/?refer=my_affiliate_id
This would be fine, except that the site offers no tracking for the ads, so I can't tell how many clicks I am getting. I could easily implement my own tracking by changing the original link href value to a php script which increments some click stats in a database and then redirects the user to the original page. Like so:
<?php // Do database updating stuff here
Header("Location: http://www.site_name.com/?refer=my_affiliate_id");
?>
But I have read some articles that say that using redirects may be seen by google as a sign of 'blackhat' techniques and they might rank me lower, unindex my site or even hurt the site that I'm redirecting too.
Does anybody know if this is true, or have any idea of the best way I could go about this?
Many thanks in advance
Joe
You could always do what Google does with search results. They have the link href normal, until the mousedown event. something to the effect of:
adlink.onmousedown = function(e) {
var callingLink = /* stuff to actually get the element here */;
callingLink.href = 'http://mysite.com/adtrack_redirect_page.ext?link=' + escape(callingLink.href);
}
Or something like that :P
So, Google will see a normal link, but almost all users will be redirected to your counter page.
Using a 301 redirect simple tells Google that the website is permamently moved. It should have, according to most random people on the internet and according to Google itself, no effect on your page-rank.
Actually I've read (can't remember where exactly) that this kind of redirect DOES HURT your rating. No, it won't "kill" your website nor the referenced, as far as I know (and please do check further), but it will hurt your site's rating as I said.
Anyway I'd recommend using some javascript to refer anything out of you domain - something like "window.open(....)" should do the trick, as Google will not follow this code.
There, refer to your tracking script which will redirect further.
You could use a javascript onClick event to send an ajax signal to your server whenever the link is clicked. That way the outgoing link is still fully functional, and your server-side script can increment your counter to track the clickthrough.

Categories