Jump to content

sajjurocks

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sajjurocks's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Alright freaks, I figured out myself. trim() on the password was needed.
  2. Hello, What I am trying to do: [*]Read "userz.txt" for username:password combination [*]Login to a site (by submitting a form) using my CURL class [*]Stay login with current user and submit another form [*]Login using the second username:password combination [*]Repeat the steps. Here is my code: <?php class Curl { public $cookieJar = ""; // Make sure the cookies.txt file is read/write permissions public function __construct($cookieJarFile = '/home/public_html/example/temp/cookie.txt') { $this->cookieJar = $cookieJarFile; } function setup() { $header = array(); $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7'); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header); curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieJar); curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookieJar); curl_setopt($this->curl, CURLOPT_AUTOREFERER, true); curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); } function get($url) { $this->curl = curl_init($url); $this->setup(); return $this->request(); } function getAll($reg, $str) { preg_match_all($reg, $str, $matches); return $matches[1]; } function postForm($url, $fields, $referer = '') { $this->curl = curl_init($url); $this->setup(); curl_setopt($this->curl, CURLOPT_URL, $url); curl_setopt($this->curl, CURLOPT_POST, 1); curl_setopt($this->curl, CURLOPT_REFERER, $referer); curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields); return $this->request(); } function getInfo($info) { $info = ($info == 'lasturl') ? curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL) : curl_getinfo($this->curl, $info); return $info; } function request() { return curl_exec($this->curl); } } ?> <?php $referer = "http://www.google.com.com"; $file = fopen("userz.txt", "r") or exit("Unable to open file!"); //while loop begins while(!feof($file)) { $curl = new Curl(); $data = fgets($file); $info = explode(":",$data); //new values for user $newdesc = "I'm new here."; $newurl = "http://mysite.com"; //for login session $url = "http://www.example.com/login.php"; $fields = "UN=$info[0]&PW=$info[1]"; //for profile page $profileurl = "http://www.example.com/profile.php"; $profilefields = "update_description=$newdesc&update_url=$newurl&submit=Submit"; //unleash the hell $html = $curl->postForm($url, $fields, $referer); $html2 = $curl->postForm($profileurl, $profilefields, $referer); } echo $html2; ?> What problem I am facing: It reads the file correctly. But the second form is submitted for only the LAST username:password combination. For example, if userz.txt file contains.. user1:pass1 user2:pass2 user3:pass3 Then the profile of only user3 will be updated. I am unable to figure out the bug in the code. I shall be thankful if anybody could identify the problem and possibly provide the solution. Thank you.
  3. How can I use values from two associative arrays (i.e. from links and titles array) in one foreach loop? That's what I am trying to do.
  4. Okay. I'm a newbie and learning, so don't expect a perfect code or even a good one. Anyway here it is (simplified version): HTML: <form name="input" action="" method="post"> Link# 1: <input name="url[]" size="80" type="text" /><br /> Title# 1: <input name="title[]" size="80" type="text" /><br /><br /> Link# 2: <input name="url[]" size="80" type="text" /><br /> Title# 2: <input name="title[]" size="80" type="text" /><br /><br /> Link# 3: <input name="url[]" size="80" type="text" /><br /> Title# 3: <input name="title[]" size="80" type="text" /><br /><br /> . . . . . . . . . . (Users can add as many pairs of links and titles as they wish by clicking "Add" button which works with the help of javascript) <input type="button" value="Add More" onClick="addInput('dynamicInput');" /> <input value="Generate!" name="submit" type="submit" /> </form> PHP: <?php require('./functions.php'); $links = $_POST['url']; $titles = $_POST['title']; //$vlinks = array_combine($links, $titles); $vlinks = array_combine(array_values($titles), array_values($links)); //print_r($vlinks); foreach($vlinks as $title => $link) { if(strlen($link) >= 1 && strlen($title) >= 1) { switch(detectSite($link)) { case 'youtube': $elink = youtube($link,str_replace(" ","-",$title)); if($elink == 404) { echo "[Error] Video URL isn't valid!"; } else { echo $elink; } . . . . . . . . . . . . ((More cases like above.)) } } else { echo "[Error] Please write both: URL and title."; } } ?> And thank you again for being so helpful.
  5. Alright. Thank you everybody. I got my answer. I will use some other way to get it done.
  6. Thank you xyph. Did you read my first post? I'm quoting some text from my first post.
  7. So there is no way to keep duplicate keys in an array? Perhaps, it can be done by creating a custom small function or something like that? I'm a beginner so I don't exactly know how it can be done. I'm actually getting data from user in a pair of input fields which gets stored in two different arrays. All I want is to combine both arrays such that values of first array should become "keys" of resultant array and values of second array should become "values" of resultant array. Thanks for your reply though it didn't solve my problem.
  8. Okay, I have two associative arrays. (data comes from post) Let's say: $arr1 = array('1' => "a", '2' => "b", '1' => "c"); $arr2 = array('1' => "x", '2' => "y", '2' => "y"); My desired result after combining: $arr3 = array('a' => "x", 'b' => "y", 'c' => "y"); Note that duplicates exist in both arrays. I just want to ignore those duplicates and generate result as mentioned above. "array_combine" does exactly the same thing. But problem is that in case of duplicates, latter one prevails. I just want the same functionality as "array_combine" but it should keep duplicates as they are. (order also matters)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.