Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:05:21+00:00 2026-05-27T17:05:21+00:00

I have set up a login area on my PHP server. The members.php file

  • 0

I have set up a login area on my PHP server. The members.php file requires login; after I login a session is created. The session lasts for a while. I want to make this work so that while the session is still valid the java applet should be able to access members.php page.

I have embedded the Java applet into the members.php page. It makes a HttpURLConnection request, however when I get the response I find that it was redirected by the PHP server to the login page.

How do I set this up correctly?

Here is the Java Applet code:

import java.applet.Applet;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

import javax.swing.JFrame;
import javax.swing.JTextArea;

public class phpConnectApplet extends Applet {

    private static final long serialVersionUID = 1L;

     public void init() {
         URL url = null;
         try {
             url = new URL("http://www.example.com/members.php");
             URLConnection urlConn = url.openConnection();
             HttpURLConnection httpConn = (HttpURLConnection) urlConn;
             httpConn.setDoOutput(true);
             httpConn.setDoInput(true);
             httpConn.setUseCaches(false);
             httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
             DataOutputStream output = new DataOutputStream(httpConn.getOutputStream());
             String content = "action=blah"; //just to test the PHP file
             output.writeBytes(content);
             output.flush();
             output.close();

             DataInputStream in = new DataInputStream(urlConn.getInputStream());
             BufferedReader input = new BufferedReader(new InputStreamReader(in));
             String str, result = "";
             while ((str = input.readLine()) != null) {
                 result = result + str + "\n";
             }
             input.close();

             Map<String, List<String>> headers = httpConn.getHeaderFields(); 
             List<String> values = headers.get("Set-Cookie");
             String cookieValue = null; 
             for (String v:values) {
                  if (cookieValue == null)
                       cookieValue = v;
                   else
                       cookieValue = cookieValue + ";" + v;
             }
             System.out.println(cookieValue);

             JFrame f = new JFrame("App Title");
             f.add(new JTextArea(result));
             f.setMaximumSize(new Dimension(400,300));
             f.pack();
             f.setLocationRelativeTo(null);
             f.setVisible(true);
         } catch (MalformedURLException me) {
             me.printStackTrace();
         } catch(IOException ie) {
             ie.printStackTrace();
         } catch(Exception e) {
             e.printStackTrace();
         }
     }

}

The output for this is a JFrame with one JTextField which contains the output HTML of the login page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:05:22+00:00Added an answer on May 27, 2026 at 5:05 pm

    You need to capture the value of your PHPSESSID cookie (or whatever you are using for the cookie name) and add it to the request in the HttpURLConnection. This MAY come through as a system parameter, but if not, you can embed the session ID as an applet attribute on the page launching the applet. (I haven’t experimented with this part specifically)

    Here’s a tutorial that explains how to send cookies in the URLConnection class: http://www.hccp.org/java-net-cookie-how-to.html

    Specifically see the section titled Setting a cookie value in a request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have set up a login page that verifies the user's credentials, and
I have a login window with a Sign In button which is set as
I have set the FlushMode property on an NHibernate session to FlushMode.Never, but when
I would like to set up a login area for my clients at my
I have got my website loggin user activity into a .txt file. I want
I am using the core Auth component. I have created a user login that
I have some logic that depends upon two properties being set, as it executes
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I
I have set up transactional replication between two SQL Servers on different ends of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.