Solved

curl, login and session maintainig

Posted on 2010-11-19
4
394 Views
Last Modified: 2012-06-27
i have a form to which need to login and maintain session for subequent url, below is the sample form
<form name="login_form" action="https://www.domain.com/login.php" method="post">
								<input name="username" value="Username" onblur="javascript: if(this.value=='') { this.value='Username';}" onfocus="javascript: if(this.value=='Username') {this.value='';};" />
														<input type="password" name="passwd" value="Password"  onfocus="javascript: if(this.value=='Password') {this.value='';};"  />
								<p></p>
														<input type="submit" value="Login"/>
															</form>

Open in new window

0
Comment
Question by:rajccs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Romi Kuntsman
ID: 34172462
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 34172491
In https://www.domain.com/login.php simply put at the top:

<?php
  if (isset($_POST['submit'])){
    session_start();
    $username = $_POST['username'];
    $password = $_POST['password'];
    //validate username and passowrd here
    $_SESSION['username'] = $username;
    $_SESSION['password'] = $password;
  }
?>


Cheers
0
 
LVL 4

Expert Comment

by:Romi Kuntsman
ID: 34172526
marqusG:
I believe that rajccs wants their page to perform a login to another page, then maintain the logged-in session for that other page. Not to allow other to login to their page.
0
 
LVL 13

Accepted Solution

by:
dsmile earned 500 total points
ID: 34172614
Change your form action form
action="https://www.domain.com/login.php"
to
action="dologin.php"

Below is sample dologin.php

Assume that remote host's login page accept 'username' and 'passwd' as input data
<?php
if (isset($_POST['username'])){
// create new curl session
$sessions = curl_init();

//init
$uri = 'https://www.domain.com/login.php'; //your URL here
$postData = array('username' => $_POST['username'], 'passwd' => $_POST['passwd']); //login data stored in array format. eg: array("name" => "test", "pwd" => "test")

// set options for logging in and store cookie
curl_setopt($sessions, CURLOPT_URL, $uri);
curl_setopt($sessions, CURLOPT_POST, 1);
curl_setopt($sessions, CURLOPT_POSTFIELDS, $postData);
curl_setopt($sessions, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($sessions, CURLOPT_FOLLOWLOCATION, 1); //auto redirect after logged in
curl_setopt($sessions, CURLOPT_HEADER, 1);
curl_setopt($sessions, CURLOPT_RETURNTRANSFER, 1);

//do logging in

curl_exec($sessions);
}

Open in new window

0

Featured Post

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question