Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get_meta_tags not working for same domain or origin

I am trying to use get_meta_tags function to fetch meta info of url. it is failed to give me meta info of url from same origin or domain.

like i am doing it from a controller http://example.com/fetch

$tags=get_meta_tags("http://example.com/blog/my-awesome-blog-post");
print_r($tags);

trying to get metainfo of a page on my site http://example.com/blog/my-awesome-blog-post. Sharing two screenshots:

Dev instance error: Dev error

Local Instance:

Local Image

Getting error like failed to open stream: Redirection limit reached, aborting. This is the error i am getting.

I tried with different urls (Except facebook). I am getting successful results.

Is there anyway i can achieve this functionality.

like image 560
saikiran Avatar asked Oct 29 '22 21:10

saikiran


1 Answers

I don't know about your localhost but this is what I have deduced from your scenario.

Your website(or the page you are accessing) keep redirecting to a new URL every time PHP tries to access the url. When, the limit of max redirection i.e. 20 is reached PHP stops following and gives you the error.

This is happening because PHP request is a simple http request which is not handling any session/cookies values. So, Your website always treats it as a new request and keeps redirecting.

To verify, Please note that when you open your URL(https://dev.kidengage.com/library) in a incognito window it redirects you to https://dev.kidengage.com/hyderabad to set location for the user. And, after cookies are set, no more redirections takes place for the given URL.

This is where redirections are happening.

So, you need to fix this first or write a custom CURL script to fetch the data which can handle the session as well as redirections.

Hope it would help.

like image 69
Parantap Parashar Avatar answered Nov 13 '22 22:11

Parantap Parashar