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 6259
Hey Markus,
I thought so..
Well, will try using regular expressions to match and replace links and see what happens..
Thanks for replying.
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...
|
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...
|
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...
|
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...
|
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...
|
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:
...
|
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...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
| |