Med detta vill du ha sagt?
Är det ett script du vill posta så gör du det i scriptforumen. :)
Frågan#1
<?php
/*
LunarClass v.0.1
--------------------
date: 2003-11-29
by: Anders Uddenberg
mail: ludberg dot libbli dot com
www: [url]http://www.libbli.com[/url]
Dependencies:
---------------------
libcurl (Get@: [url]http://curl.haxx.se/libcurl/php/[/url])
Features:
-----------------
login on lunarstorm.se
get the guestbook
get a user's userid (ex: {F972EDE5-9A90-4AD4-B243-1D780D9F6DD7} )
get any page hosted by lunarstorm (what variables and values that should be sent is up to you)
Function:
-----------------
send_message( username )
- Write in a specific users guestbook
get_usderID( username )
- Get someones userID
set_info( username, password)
- Set you username and password
GetCurlPage( resource ch, url )
- Use GET method with cURL
GetPostPage( resource ch, url, post-data )
- Use POST method with cURL
lunarstorm()
- Initialize a new session and return a CURL handle
return_user()
- Return the username
return_pass()
- Return the password
return_ch()
- Return the handler
login()
- Easy way to login on lunarstorm. NOTE: You have to use set_info() before!
get_guestbook( login return )
- Easy way to you guestbook. NOTE: You have to use set_info(), and login() before. You don't have to use login before using thie function.
validate()
- Validate the settings. NOTE: This function is beeing used in login() and get_guestbook(). It's strongly recommended you use this one before using GET/POST -CurlPage()
Tips:
---------------
cURL webpages:
- [url]http://www.php.net/curl[/url]
- [url]http://curl.haxx.se[/url] (official)
*/
class lunarstorm {
##-- Variables
#- Username
var $username = "";
#- Password
var $password = "";
var $data = "";
var $ch = "";
var $login_status = 0;
##-- Write to someones guestbook
function send_message($user, $message) {
#-- Check if you're logged in
if($this->login_status == 0) {
die("send_message() error: You must login before you can use this function. See login()");
}
#-- Check that $user isn't emtpy or null, and is a valid string
if(empty($user) || $user == "" || $this->validate($user) != TRUE) {
die("send_message() error: You must specify a username");
}
#-- Check so $message isn't null, empty or <10 tokens
if(strlen($message) < 10) {
die("send_message() error: Your message must be longer than 10 tokens");
}
#-- retrieve the user's userid
$userid = $this->get_userID($user);
#-- build the datastring
$data = "guestnr=&userid=".$userid."&value=".user."&source=page&msgbody=".$message;
$this->PostCurlPage($this->ch, "http://www.lunarstorm.se/usr/gst_store.asp", $data);
} // send_message()
##-- Get some users userID
function get_userID($user) {
#-- Check if you're logged in
if($this->login_status == 0) {
die("get_userID() error: You must login before you can use this function. See login()");
}
#-- Check that $user isn't empty or null, and is a valid string
if(empty($user) || $user == "" || $this->validate($user) != TRUE) {
die("get_userID() error: You must specify a username");
}
$temp = $this->GetCurlPage($this->ch, "http://www.lunarstorm.se/_inc/sub_quickfind_db.asp?user=".$user);
#-- Extract the userid
preg_match("/\{[0-9a-z-]*\}/i",$temp , $match);
return $match[0];
} // get_userID
##-- Validate the username and password
function validate($string) {
if(!ereg("^[a-zA-Z0-9]+$", $string)) {
die("Your string can only contain: a-z, 0-9, A-Z");
} else {
return TRUE;
}
} // validate
##-- Set username and password
function set_info($username = '', $password = '') {
$this->username = ($username != '') ? $username : $this->username;
$this->password = ($password != '') ? $password : $this->password;
}
#-- Use GET method with cURL
function GetCurlPage($ch, $pageSpec) {
#-- What agent should be sent
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n";
#-- What accept should be sent
$header[] = "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*\r\n";
#-- Define the URL
curl_setopt($ch, CURLOPT_URL, $pageSpec);
#-- Return the transfer instead of printing it out
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
#-- Add the header to $ch
// curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
#-- Add the referer to $ch
// curl_setopt($ch, CURLOPT_REFERER, "http://www.lunarstorm.se\r\n");
#-- Add the useragent to $ch
// curl_setopt($ch, CURLOPT_USERAGENT, $agent);
#-- Add the host to $ch
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Host: [url]http://www.lunarstorm.se\r\n[/url]");
#-- Make the script follow any header("location: xxx");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
#-- Initiates a cookie file
curl_setopt($ch, CURLOPT_COOKIEJAR, "cook");
#-- Uses cookies from previous
curl_setopt($ch, CURLOPT_COOKIEFILE, "cook");
#-- Perform GET
$temp = curl_exec($ch);
return $temp;
} // GetCurlPage()
##-- Use POST method with cURL
function PostCurlPage($ch, $pageSpec, $data) {
#-- What agent should be sent
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n";
#-- What header should be sent
$header[] = "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*\r\n";
#-- Define the URL
curl_setopt($ch, CURLOPT_URL, $pageSpec);
#-- Return the transfer instead of printing it out
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_VERBOSE, 1);
#-- Add the header to $ch
// curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
#-- Add the referer to $ch
// curl_setopt($ch, CURLOPT_REFERER, "http://www.lunarstorm.se\r\n");
#-- Add the useragent to $ch
// curl_setopt($ch, CURLOPT_USERAGENT, $agent);
#-- Add the host to $ch
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Host: [url]http://www.lunarstorm.se\r\n[/url]");
#-- Make the script follow any header("location: xxx");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
#-- Initiates a cookie file
curl_setopt($ch, CURLOPT_COOKIEJAR, "cook");
#-- Uses cookies from previous
curl_setopt($ch, CURLOPT_COOKIEFILE, "cook");
#-- Set PHP to do a regular POST (application/x-www-form-urlencoded)
curl_setopt($ch, CURLOPT_POST, 1);
#-- Pass the string $data to the HTTP "POST" operation
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
#-- Perform POST
$temp = curl_exec($ch);
return $temp;
} // PostCurlPage()
function lunarstorm() {
$this->ch = curl_init();
} // init()
function return_user() {
return $this->username;
} // return_user
function return_pass() {
return $this->password;
} // return_pass
function return_ch() {
return $this->ch;
} // return_ch
function login() {
if(($this->validate($this->username) == TRUE) && ($this->validate($this->password) == TRUE)) {
#- Set the data
$data = "username=".$this->username."&password=".$this->password;
#- Get the first page in the login sequence
$first = $this->PostCurlPage($this->ch, "http://www.lunarstorm.se/log/log_login.asp", $data);
#- Get the second page in the login sequence
$second = $this->GetCurlpage($this->ch, "http://www.lunarstorm.se/log/log_inside.asp?status=login&cluster=191");
#- Get the last page in the login sequence
$third = $this->GetCurlPage($this->ch, "http://www.lunarstorm.se/top/top_inside.asp");
#- Set the login_status to 1 (1 = logged in, 0 = not logged in)
$this->login_status = 1;
return $third;
}
} //login
function get_guestbook($login) {
if($this->login_status == 0) {
die("get_gestbook() error: You must login first. See login()");
}
#-- Extract the userid {............}
preg_match("/\{[0-9a-z-]*\}/i",$login , $match);
#-- Get the guestbook page
$guestbook = $this->GetCurlPage($this->ch, "http://www.lunarstorm.se/usr/gst_guestbook.asp?userID=".$match[0]);
return $guestbook;
} // get_gustbook
} // class
########################################################################
# Example. How to get my own guestbook
########################################################################
$lunar = new lunarstorm();
$lunar->set_info("ludberg","password");
$lunar->login();
$lunar->get_guestbook("ludberg");
// write output to result.html
$handle = fopen("result.html", "w");
if(!fwrite($handle, $output)) {
echo "Cannot write to file!";
exit;
}
header("location: result.html");
