Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

curl, login and session maintainig

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
rajccs
Asked:
rajccs
  • 2
1 Solution
 
Romi KuntsmanCommented:
0
 
Marco GasiFreelancerCommented:
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
 
Romi KuntsmanCommented:
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
 
dsmileCommented:
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now