Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for PHP to follow a URL?

Tags:

redirect

url

php

Is it possible for PHP to take a URL, wait for the redirects to go through, and then fetch the url of the page it's on?

like image 727
waiwai933 Avatar asked Oct 17 '09 05:10

waiwai933


People also ask

How to redirect to external URL in PHP?

Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php . You can also specify relative URLs.

How post URL in PHP?

If you're looking to post data to a URL from PHP code itself (without using an html form) it can be done with curl. It will look like this: $url = 'http://www.someurl.com'; $myvars = 'myvar1=' . $myvar1 .

How to redirect page using id in PHP?

urlencode($current_id['id']); ?> Show activity on this post. All you need to do is pass a string to the Location . And with your code, it will redirect to the location specified by the string, not to print it.

How to find the certain string in an URL using PHP?

Program: PHP program to find the certain string in an URL using strpos () function. Note: The strpos () function finds the sub string in a text using string matching method. Sometime it gives undesired result.

How to get the full URL in PHP?

To get the full URL in PHP – $full = (isset ($_SERVER ['HTTPS']) ? "https://" : "http://"). $_SERVER ['HTTP_HOST']. $_SERVER ['REQUEST_URI']; To remove the query string from the full URL – $full = strtok ($full, "?"); That should cover the basics, but if you need more specific “URL parts” – Read on for more examples!

What is PHP url and how to handle it?

This PHP URL also has many URL functions to handle which are useful in handling the URL like encoding, decoding, parsing, etc. based on our requirement. Usually, there will be two types of URLs.

How to validate a URL in PHP?

In this short tutorial, you will find the easiest and most efficient way to validate a URL with the help of PHP. Check out the options below. The first efficient way of validating a URL is applying the filter_var function with the FILTER_VALIDATE_URL filter.


1 Answers

    $cr = curl_init("http://example.com"); 
    curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($cr, CURLOPT_FOLLOWLOCATION, 1);     
    curl_exec($cr); 
    $info = curl_getinfo($cr);
    echo "url=".$info["url"];
like image 63
serg Avatar answered Oct 25 '22 00:10

serg