Question about header( "Location:http://

11 replies
Hi,

Actually, I have a slightly different question.
If I use header( "Location:, it will redirect the browser to the URL specified.

I only want to call the URL, not redirect the browser. How can I accomplish that?

Thanks in advance for your help!
  • Profile picture of the author Shounak Gupte
    if you are using PHP, have a look at cURL library.
    Signature
    Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
    {{ DiscussionBoard.errors[2088807].message }}
  • Profile picture of the author Shounak Gupte
    this will just call the url instead of going to it!

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.google.com");
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $result = curl_exec ($ch);
    curl_close ($ch);
    Signature
    Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
    {{ DiscussionBoard.errors[2088814].message }}
  • Profile picture of the author Manfred Ekblad
    ...and in case you don't have cURL installed, you can use:

    <?php
    $handle = fopen("http://www.google.com/", "rb");
    $contents = stream_get_contents($handle);
    fclose($handle);
    ?>
    {{ DiscussionBoard.errors[2088939].message }}
    • Profile picture of the author Shounak Gupte
      Originally Posted by Manfred Ekblad View Post

      ...and in case you don't have cURL installed, you can use:

      <?php
      = fopen("http://www.google.com/", "rb");
      = stream_get_contents();
      fclose();
      ?>
      exactly!!
      Signature
      Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
      {{ DiscussionBoard.errors[2088961].message }}
      • Profile picture of the author RokNStoK
        Thank You Both Shounak and Manfred!

        I've run out of time tonight... but I will definately give these a try tomorrow and report back!

        I'm inclined to use the simpler solution which seems to be fopen. Are there any disadvantages to going this route?

        You guys are great! Thanks again for your quick help!
        Signature
        Ken
        www.monopolinks.com
        Free One-Way Link Exchange
        {{ DiscussionBoard.errors[2089214].message }}
  • Profile picture of the author Manfred Ekblad
    Not really, I was thinking that perhaps you couldn't POST data using fopen, but then I remembered this: HTTP POST from PHP, without cURL - Evil, as in Dr.

    Bonus: It mentions an even simpler solution for most cases!

    $page = file_get_contents('http://www.google.com/');

    nice!
    {{ DiscussionBoard.errors[2089281].message }}
    • Profile picture of the author RokNStoK
      Well, I'm trying to get filegetcontents to work... with a twist. Here is the HTML

      <a href=http://www.anyurl.com/ target="_blank" onclick="filegetcontents('http://www.specificurl.com/filename.php');">Anchor Text</a>

      To my understanding, this should first call 'specificurl', and then open 'anyurl' in the browser. But I can't seem to get it to work. Can anybody see an obvious syntax error?

      Thanks for your help!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2092647].message }}
  • Profile picture of the author Manfred Ekblad
    Ah...

    Well, that won't work, simply because you are mixing php, html and javascript in a creative but incorrect way.

    What you need to do is to create a php-file where you call the filegetcontents('http://www.specificurl.com/filename.php');

    Then skip the whole "onclick" thing and just point the URL to that php-file.

    Outline:

    1. Create a php file with filegetcontents('http://www.specificurl.com/filename.php'); on your server and name it getpage.php:

    <?php

    echo filegetcontents('http://www.specificurl.com/filename.php');

    ?>

    2. Make the link on your site look like this, without the onclick:

    <a href="http://www.anyurl.com/getpage.php" target="_blank">Anchor Text</a>

    -------

    Now, when the visitor clicks on the link, the getpage.php is called and that one simply reads from the other page and shows the result to the visitor.

    I hope that helps
    {{ DiscussionBoard.errors[2092773].message }}
    • Profile picture of the author RokNStoK
      Thanks for responding again Manfred! i appreciate your help.

      Maybe it would help if I explained my problem.

      I want to 'track clicks'. In other words, if somebody clicks an outbound link on my site, I want to not only open a new browser with the target URL, but I also want to call another URL which will increment a counter for the link and update the DB.

      In this way, I can track not only traffic for my site, but also track clickthrough ratio for different advertisers. At the same time, the <a tag is still readable by the search engines for SEO... right?

      Probably an easier way to get it done?

      Thanks again Manfred!

      Ken
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2092804].message }}
  • Profile picture of the author Manfred Ekblad
    Oh... I see

    Yes, that's achievable but there are easier ways to do it than the one's suggessted above.

    I'll just get some sleep first

    Back in some hours...

    PS. If you add me on Skype we can make progress a lot faster, because then we can sort out any questions directly.

    Skype: manfred.ekblad
    {{ DiscussionBoard.errors[2099640].message }}
    • Profile picture of the author RokNStoK
      Hi Manfred! I'm glad to hear there's something better! I don't have a Skype account... and can't really deal with another learning curve 'right now'. Plus, I don't want to monopolise your time. There's no rush on this particular project... just when you have a chance. I do have a telephone if that would be a better use of your time.

      I appreciate your help!
      Signature
      Ken
      www.monopolinks.com
      Free One-Way Link Exchange
      {{ DiscussionBoard.errors[2100156].message }}

Trending Topics