plz help auto get strings

Discussion in 'PHP' started by tarekfathey, Aug 31, 2010.

  1. #1
    help please

    I want to make acode

    that have auto get function

    example

    $urls = array(
    1 => "http://example.com",
    2 => "http://example1.com",
    3 => "http://example3.com",

    and when i request the urls
    it 'll be auto changed at every time i request $urls

    please any person help me
     
    tarekfathey, Aug 31, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You dont give any details as to what is available, or the URLs you are requesting but it should be pretty simple using CURL.

    E.G

    <?php
    
    $urls = array('http://www.example.com',
    	'http://www.example2.com');
    
    foreach($urls as $url)
    	{
    	$html = get($url);
    	# do stuff with the requested URL here. EG
    	print $html."\n-------------------------\n";
    	}
    
    function get($url)
      {
      $headers=array();
      # Add your custom headers as required, EG
      $headers[]='Connection: Keep-Alive';
      $headers[]='Content-type: application/x-www-form-urlencoded;charset=UTF-8';
    
      $process = curl_init($url);
      curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($process, CURLOPT_HEADER, false);
      curl_setopt($process, CURLOPT_USERAGENT, 'YOURUA');
      curl_setopt($process, CURLOPT_TIMEOUT, 10);
      curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt ($process, CURLOPT_SSL_VERIFYPEER, false);
      $return = curl_exec($process);
      curl_close($process);
      return $return;
      }
    PHP:
     
    lukeg32, Aug 31, 2010 IP
  3. tarekfathey

    tarekfathey Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    Thank you this is working but iwant to redirect to the requested page

    $urls = array('http://www.example.com',
    'http://www.example2.com');

    and there is an error that it's get all requested pages at the page iwant it only redirect auto to one page
     
    Last edited: Aug 31, 2010
    tarekfathey, Aug 31, 2010 IP
  4. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #4

    Im a little confused about what it is you are trying to do exactly.

    You can redirect to one of them using the header function;

    http://php.net/manual/en/function.header.php

    If you want to redirect to a random URL, something like;

    <?php
    
    $urls = array("http://www.example1.com", "http://www.example2.com");
    
    header("location: ".$urls[rand(0,(sizeof($urls)-1)));
    PHP:
    If you want to be able to specify the URL you are redirecting too, you will need to pass it through using post, get, session etc etc and then process the array in a similar way.
     
    lukeg32, Sep 1, 2010 IP
  5. leena86

    leena86 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Frnd,
    I joined to a PHP & Unix/Linux groups, which contains Materials, Jobs Interview Questions & Interview Kit for Free too. If you like it join my groups go this
    URL=. http://groups.yahoo.com/group/OneStopPHP/join
    URL=http://groups.yahoo.com/group/OneStopUNIX/join
     
    leena86, Sep 1, 2010 IP