cURL/login help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

cURL/login help

Post by neoaddict »

Here's my current code:

Code: Select all

<?php

$ch = curl_init("http://neopets.com/login.phtml?username=TEST&password=TEST&destination=/stockmarket.phtml");
$fp = fopen("grabthetext.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, false);

$something = file_get_contents("http://neopets.com/stockmarket.phtml");
$something = preg_match("#<marquee>(.*)<\/marquee>#i", $retrievedhtml, $match);

curl_exec($ch);
//echo $something;

//echo $match[0];

curl_close($ch);
fclose($fp);

file_get_contents("grabthetext.txt", "r");
?>
This code prevents the script from logging in:

Code: Select all

<script name = 'JavaScript'>
		<!--


		var subcount = 0;

		function one_submit()
		{
			 if (subcount == 0)
			 {
				  subcount++;
				  return true;
			 }

			 else
			 return false;
		}

		//-->
		</script>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

o.O

What are we supposed to help with?
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Does the cURL stuff look right and how could I allow the script to login without interference from the javascript?
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Code: Select all

<script name = 'JavaScript'>
      <!--


      var subcount = 0;

      function one_submit()
      {
          if (subcount == 0)
          {
              subcount++;
              return true;
          }

          else
          return false;
      }

      //-->
      </script>
How can I bypass this Javascript? It's what's blocking my login.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how is it being used?
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

If you're talking about the JS, I don't really know.


If you're talking about my script, it's for a site portal.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It would be nice to know how the Javascript is being used..
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Personally, I'm not too much of a JS coder, but I think it checks whether you pressed submit or not.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unless that is used in the submission data, it shouldn't have any baring on curl..
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

I can't think of anything else that might be causing the problem.

Code: Select all

<?php

header('Content-Type: application/x-www-form-urlencoded');

$ch = curl_init();

curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, 'http://neopets.com/login.phtml?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=TEST&password=TEST&destination=/stockmarket.phtml");

//$something = file_get_contents("http://neopets.com/stockmarket.phtml");
//$something = preg_match("#<marquee>(.*)<\/marquee>#i", $retrievedhtml, $match);

curl_exec($ch);
curl_error($ch);

curl_close($ch);

?>
That's my most current code, but it won't login.

It keeps on returning a bad password page, but I'm sure it's the right password.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the urls appear to be off, at least from what I can tell in the quick look I did..
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

How are they off?
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Bump.
neoaddict
Forum Commoner
Posts: 44
Joined: Thu Jan 12, 2006 12:28 pm

Post by neoaddict »

Bump.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

The problem you have to solve is why the site accepts the value when they are posted by your browser and when they are posted by your script (curl). As you will notice when you search for similar problems is that a browser sends a couple of extra headers (eg: User-Agent). I'm pretty sure that neopets discriminates based on that header (amongst others). Now it's your task to try them all (and combinations of them) out ;) And see what works and what not.
Post Reply