Hi all,
I am using cURL for the first time. I need to login to a site and my cURL code to do the same is as follows:
//curlScript.php -
<?php
-
function getContent($url, $referer, $cookie_file_name, $post_fields='')
-
{
-
-
//Setting cookie path
-
if (substr(PHP_OS, 0, 3) == 'WIN')
-
{
-
if($cookie_file_name != "")
-
{
-
$cookie_file_path = str_replace('\\','/', getcwd().'/'.$cookie_file_name);
-
}
-
else
-
{
-
$cookie_file_path = str_replace('\\','/', getcwd().'/cookies.txt');
-
}
-
}
-
else
-
{
-
if($cookie_file_name != "")
-
{
-
$cookie_file_path = tempnam("/tmp", $cookie_file_name);
-
}
-
else
-
{
-
$cookie_file_path = tempnam("/tmp", "cookies");
-
}
-
}
-
-
//Creating the cookie file if it doesn't exist
-
$fp = fopen($cookie_file_path, "w");
-
fclose($fp);
-
-
//Spoofing user-agent
-
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20";
-
-
//Initializing cURL session and setting appropriate options
-
$ch = curl_init($url);
-
-
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
-
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
-
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
-
-
if($post_fields != '')
-
{
-
curl_setopt($ch, CURLOPT_POST, 1);
-
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_fields);
-
}
-
-
if($referer != '')
-
{
-
curl_setopt($ch, CURLOPT_REFERER, $referer);
-
}
-
-
//Executing cURL session and getting the o/p string
-
$result = curl_exec ($ch);
-
-
//Close the cURL session
-
curl_close ($ch);
-
-
//Return content fetched by the cURL session
-
return $result ;
-
-
}//getContent()
-
?>
-
I have xampp installed on my localhost and right now I am executing the script there.
I did manage to login to my account, however, when I click on any of the links in the fetched content, it tries to redirect to some resource on my localhost and consequently gives the 404-object not found error.
Looking at the grabbed content I realized that all the links there have relative paths, hence 'http://localhost' gets prepended automatically.
Is replacing all relative paths with absolute paths the only way to make the links work? But in any case, my browser address bar still shows http://localhost/curlScript.php, so do I need to redirect to the appropriate
page after logging in.. I mean how would that work.. am I missing something?
I am a little confused, any help highly appreciated!!!
Thanks!
3 6285
Hey Markus,
I thought so..
Well, will try using regular expressions to match and replace links and see what happens..
Thanks for replying.
Markus 6,050
Recognized Expert Expert @buzz2050
No problem.
Greetings,
Markus.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Yandos |
last post by:
Hello all,
I'm sorry for a bit off-topic post, but curl does not have own newsgroup, so I hope someone might
help me here...
I need to feed form like the following using libcurl:
<form action="file-upload.php" method="post" enctype="multipart/form-data">
<input name="senderid" value="1111" type="hidden">
<input name="senderpass"...
|
by: mahesh anasuri |
last post by:
Hi all,
I am new to this mailing list. Thankful if any one is using curl/linux version to and worked on Https.
I have created certificates (PEM format) for client and server using openSSL. I am using Apache server/Linux platform and started server with "server certificate". I configured server to listen HTTPS service at port 443.
I...
|
by: Raj |
last post by:
Hi,
I am newbie to programming with libcurl. the problem is i want to send
my gmail username and password outside the browser and get access to my
mail. this i am doing with LibCurl. Though i dont get any errors, i am
nt able to get the o/p Can anyone kindly help. i will attach the
program here
#include <curl/curl.h>
#include <curl/types.h>...
|
by: Giuseppe |
last post by:
Hi everybody,
this is my first post in this group since it is from little time that I
have begun to learn c++.
My problem is to post a web form using the libcurl library.
The form is at this address: http://it.mobi.dada.net/lostpassword.php
end it isn't very complicated:
<form method="post" action="/cgi-bin/hotw/sendpassword.chm">
|
by: Uday |
last post by:
Hi,
can anybody help me uploading a file (text/zip) to a remote
server using libcurl libraries in c++. when i searched in google, i
found that i've to use CURLOPT_POST, CURLOPT_INFILE which points to
the actual file & READFUNCTION which reads the content from the file
and puts in the buffer. i'm setting the file size also in...
| |
by: JDS |
last post by:
So, I'd like to create the following scenario:
1) Use cURL library within PHP (cURL + "Cookie Jar", et.al) to create a
virtual browser session that "logs in" to a remote site. (For example:
here:
http://curl.haxx.se/libcurl/php/examples/cookiejar.html
and here:
http://curl.haxx.se/libcurl/php/examples/ebay_login.html
|
by: sharanraman |
last post by:
how to send data to a HTTP web server using libcurl
|
by: Choi |
last post by:
Good morning.
I've tried to extract, using libcurl, web pages but it failed. There
is no compilation error concerning the class I wrote, but the problems
appear when I compile a main method which calls this class.
My class :
**********************************libcurl_tools.h
|
by: Jake |
last post by:
Hi,
I am trying to make an application in C which must establish a telnet
session
with a remote server, execute some scripts on the remote server and close
down
the telnet session.
I have had a look at libcurl since it supports several protocols, but I
haven't been
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |