Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP > PHP Application Design
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Oct 27, 2008, 08:38   #1
jpollar
SitePoint Enthusiast
 
Join Date: Apr 2008
Posts: 33
Smile Help me with wget: Get a FREE Rapidshare Premium Account

FREE Rapidshare Premium Account to the first person that helps me fix this.

I'm having serious problems getting my php scripts to work correctly when calling via wget. I'm not getting errors, the results are just wrong.

When I take the URL below (see calling page) and just execute within a browser, it works correctly by retrieving the current users rapidshare account. Using wget doesn't obtain the users account for some reason and connects to the back up account (see action page).

Is there a reason why calling a script from your browser and using wget would provide different results? Is there something I'm doing wrong in the wget call?

Please help...if you can.

Thanks.

Calling Page

Code:
<?php

$key = "7928385";
$userid = "jpollar";

$result = exec("wget -b http://www.uploadjockey.com/~uploadin/rapidshare.com.php?key=".$key."&username=".$userid);
echo $result;
					
?>
Action Page

Code:
<?
//error_reporting(0);
ignore_user_abort(1);
set_time_limit(0);

include "admin/config.php";
include "conn.php";
include "function.php";
include "functions.php";

@ini_set('memory_limit', '1024M');
@ob_end_clean();
ob_implicit_flush(TRUE);

$key = ereg_replace("[^A-Za-z0-9]", "", $_REQUEST['key']);
$username = $_REQUEST['username'];

// MYSQL Connect
$conn = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
@mysql_select_db(DB_DATABASE);

$files = mysql_query ("select * from files where `key` = '".$key."'");
$row = mysql_fetch_array($files);

if ($row['filename'] == "" || $row['rs'] != "")
{
	die();
}

//Check for user Rapidshare Account
$rspremium = mysql_query ("select * from users where `username` = '".$username."'");
$rsrow = mysql_fetch_array($rspremium);

$login = $rsrow['rsid'];
$password = $rsrow['rspass'];

if ($login == "")
{
// Backup Rapidshare Premium Login Details
$login = "backupuser"; // << Username here
$password = "backuppass"; // << Password here
}

$target = realpath(SITE_PATH . UPLOAD_FOLDER . $row['filename']);

$server = file_get_contents("http://www.rapidshare.com");
$rss =  cut_str($server,'action="','"'); // to choose available server given by rapidshare
if ($rss == "")
{
	$rss = "http://rs368l3.rapidshare.com/cgi-bin/upload.cgi";
}

			$post_data['filecontent']		= "@".$target;		
			$post_data['login'] = $login;
			$post_data['password'] = $password;			

			$ch = curl_init($rss);  
		  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		   
		  $postResult = curl_exec($ch);
		  curl_close($ch);
			   
		  echo $postResult;
			$download_link=cut_str($postResult,'<div class="downloadlink">','</div>');
// If sometime premium expired and you forget to renew account, it will start uploading without premium.

if($download_link == "")
{
	
	require('class.XMLHttpRequest.php');
	$req = new XMLHttpRequest();
	$req->open("POST","https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi");
	$req->setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	$req->send("login=".$login."&password=".$password);
	preg_match("/user=[^;]*/i", $req->getResponseHeader('Set-Cookie'), $cookie);
	$req->open("GET","https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi?export=1");
	$req->setRequestHeader("Cookie", $cookie[0]);
	$req->send(null);
	$data = implode("\n",array_reverse(explode("\n",$req->responseText)));
	$fn = '/http.*' .$row['filename']. '/i' ;
	preg_match($fn,$data,$res);
	$download_link = trim($res[0]);
}


if ($download_link !="")
{
	mysql_query ("UPDATE `files` SET `rs` = '" . $download_link . "' WHERE `key` =  '" . $key . "' LIMIT 1");
 	
}



?>
jpollar is offline   Reply With Quote
Old Oct 27, 2008, 13:39   #2
imaginethis
SitePoint Guru
 
Join Date: Jan 2005
Location: heaven
Posts: 948
Quote:
Originally Posted by jpollar View Post
FREE Rapidshare Premium Account to the first person that helps me fix this.

I'm having serious problems getting my php scripts to work correctly when calling via wget. I'm not getting errors, the results are just wrong.

When I take the URL below (see calling page) and just execute within a browser, it works correctly by retrieving the current users rapidshare account. Using wget doesn't obtain the users account for some reason and connects to the back up account (see action page).

Is there a reason why calling a script from your browser and using wget would provide different results? Is there something I'm doing wrong in the wget call?

Please help...if you can.

Thanks.

Calling Page

Code:
<?php

$key = "7928385";
$userid = "jpollar";

$result = exec("wget -b http://www.uploadjockey.com/~uploadin/rapidshare.com.php?key=".$key."&username=".$userid);
echo $result;
					
?>
Action Page

Code:
<?
//error_reporting(0);
ignore_user_abort(1);
set_time_limit(0);

include "admin/config.php";
include "conn.php";
include "function.php";
include "functions.php";

@ini_set('memory_limit', '1024M');
@ob_end_clean();
ob_implicit_flush(TRUE);

$key = ereg_replace("[^A-Za-z0-9]", "", $_REQUEST['key']);
$username = $_REQUEST['username'];

// MYSQL Connect
$conn = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
@mysql_select_db(DB_DATABASE);

$files = mysql_query ("select * from files where `key` = '".$key."'");
$row = mysql_fetch_array($files);

if ($row['filename'] == "" || $row['rs'] != "")
{
	die();
}

//Check for user Rapidshare Account
$rspremium = mysql_query ("select * from users where `username` = '".$username."'");
$rsrow = mysql_fetch_array($rspremium);

$login = $rsrow['rsid'];
$password = $rsrow['rspass'];

if ($login == "")
{
// Backup Rapidshare Premium Login Details
$login = "backupuser"; // << Username here
$password = "backuppass"; // << Password here
}

$target = realpath(SITE_PATH . UPLOAD_FOLDER . $row['filename']);

$server = file_get_contents("http://www.rapidshare.com");
$rss =  cut_str($server,'action="','"'); // to choose available server given by rapidshare
if ($rss == "")
{
	$rss = "http://rs368l3.rapidshare.com/cgi-bin/upload.cgi";
}

			$post_data['filecontent']		= "@".$target;		
			$post_data['login'] = $login;
			$post_data['password'] = $password;			

			$ch = curl_init($rss);  
		  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		   
		  $postResult = curl_exec($ch);
		  curl_close($ch);
			   
		  echo $postResult;
			$download_link=cut_str($postResult,'<div class="downloadlink">','</div>');
// If sometime premium expired and you forget to renew account, it will start uploading without premium.

if($download_link == "")
{
	
	require('class.XMLHttpRequest.php');
	$req = new XMLHttpRequest();
	$req->open("POST","https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi");
	$req->setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	$req->send("login=".$login."&password=".$password);
	preg_match("/user=[^;]*/i", $req->getResponseHeader('Set-Cookie'), $cookie);
	$req->open("GET","https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi?export=1");
	$req->setRequestHeader("Cookie", $cookie[0]);
	$req->send(null);
	$data = implode("\n",array_reverse(explode("\n",$req->responseText)));
	$fn = '/http.*' .$row['filename']. '/i' ;
	preg_match($fn,$data,$res);
	$download_link = trim($res[0]);
}


if ($download_link !="")
{
	mysql_query ("UPDATE `files` SET `rs` = '" . $download_link . "' WHERE `key` =  '" . $key . "' LIMIT 1");
 	
}



?>
The answer is javascript. Browsers understand it, wget doesn't.
imaginethis is offline   Reply With Quote
Old Oct 27, 2008, 13:47   #3
jpollar
SitePoint Enthusiast
 
Join Date: Apr 2008
Posts: 33
Thanks for the response. However, there is no javascript in either file. Nice try.

Any other ideas?
jpollar is offline   Reply With Quote
Old Oct 27, 2008, 14:11   #4
imaginethis
SitePoint Guru
 
Join Date: Jan 2005
Location: heaven
Posts: 948
Ah, sorry. I misunderstood what you were asking. Can you post a sample of the two outputs and what exactly is wrong.
imaginethis is offline   Reply With Quote
Old Oct 28, 2008, 00:26   #5
jpollar
SitePoint Enthusiast
 
Join Date: Apr 2008
Posts: 33
I've left comments in the code to show you what I think is happening. What's funny is the first query in the action page seems to be working correctly with both wget and browser. The second query (see below) only works within a browser for some reason. You can see on the calling page that I'm passing the $username value in the URL, so that shouldn't be the problem. I've confirmed that it's passing the correct url by printing the url to screen before passing via wget. Still not working right with wget.


// When the action page is executed via browswer, the query is finding the current user.
// With wget it seems to be returning nothing (see below)...I can't confirm this theory.

$rspremium = mysql_query ("select * from users where `username` = '".$username."'");
$rsrow = mysql_fetch_array($rspremium);

$login = $rsrow['rsid'];
$password = $rsrow['rspass'];

// HERE's where the problem lies.
// Since the $login variable is empty with wget, the account is set the backup account.
// This problem does not happen when I call the action page directly in a browser.

if ($login == "")
{
// Backup Rapidshare Premium Login Details
$login = "backupuser"; // << Username here
$password = "backuppass"; // << Password here
}
jpollar is offline   Reply With Quote
Old Oct 28, 2008, 08:50   #6
jpollar
SitePoint Enthusiast
 
Join Date: Apr 2008
Posts: 33
I may just have to find another solution. Users are filling up my premium accounts like gangbusters...
jpollar is offline   Reply With Quote
Old Oct 28, 2008, 09:11   #7
antirealm
SitePoint Enthusiast
 
Join Date: Oct 2008
Posts: 71
could be cookie problems?

the only thing i can suggest at this point is to create a server that listens on say port 8080 and change the URLs to point to this local server and see what the differences are between the wget request and your browser request.

it might provide a hint.
antirealm is offline   Reply With Quote
Old Oct 28, 2008, 14:48   #8
jpollar
SitePoint Enthusiast
 
Join Date: Apr 2008
Posts: 33
I'm not using cookies...I'm passing variables via url query string

Quote:
the only thing i can suggest at this point is to create a server that listens on say port 8080 and change the URLs to point to this local server and see what the differences are between the wget request and your browser request.
How exactly would this help?
jpollar is offline   Reply With Quote
Old Oct 28, 2008, 16:41   #9
cuberoot
SitePoint Addict
 
Join Date: Feb 2007
Posts: 251
try escapeshellarg() or escapeshellcmd()
cuberoot is offline   Reply With Quote
Old Oct 29, 2008, 00:27   #10
jpollar
SitePoint Enthusiast
 
Join Date: Apr 2008
Posts: 33
Cuberoot.....You're right on!

Thank you!!!!

escapeshellcmd fixed it

Let me know how I can send the rapidshare account to you!
jpollar is offline   Reply With Quote
Reply

Bookmarks

Tags
rapidshare

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 13:08.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved