Skip to main content

Posts

Showing posts with the label cookies

JAVA: How can I download an HTML file from a site that requires cookies enabled?

I'm trying to download an HTML file from a site. I'm using the following simple method: URL url = new URL("here goes the link to the html file"); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); String htmlfile = ""; String temp; while ((temp = br.readLine()) != null) { htmlfile+= temp; } The problem is that I get the following String in the htmlfile variable: The installation of ... requires the acceptance of a cookie by your browser software. The cookie is used to ensure that you and only you are able to access information .... In other words, I need to somewhat enable cookies when opening a stream from the url. Is it possible to achieve this by using URL or do I need a different method? Thanks in advance

Can we set a cookie in php according to client"s time?

I have following requirements: create a cookie for server domain that cookie will expire in x seconds say in 200 or 500 seconds. Problem is, that clients can lag as much as many minutes behind server. On server side I am setting cookie as setcookie($cooName,$cooVal,time()+500,"/"); but now if client computer is 500 seconds behind server, above code will effect into a cookie which will expire in 1000 seconds not 500 seconds. I was thinking to send client's time stamp to server and set cookie on that time. something like this: setcookie($cooName,$cooVal,$_GET['clientTS']+500,"/"); But if client is 500 seconds behind, and if I set such a cookie which is backdated it does not get set. How to achieve a time sync between client and server in case of cookie expiry?

How to implement a “save” feature with dynamic content using cookies

I would like to implement a "save" feature, which allows my users to save a particular entry that I have presented to them from my database. For example, if they see something they like, they can press the "save" button and it will save to a "bookmarks" page. Here is my code: <?php // Get all the data from the example table $result = mysql_query("SELECT * FROM table WHERE item <> 0 ORDER BY id") or die(mysql_error()); // keeps getting the next row until there are no more to get $i = 10; while ($i > 0) { $i--; $row = mysql_fetch_array( $result ); if ($row['id'] != "" ) { ?> <!-- Some content in this div--> <div class="content"> <img src="<?php echo $row['logo']; ?>"/> <?php echo $row['id']; ?> </div> <!-- This div will have the save icon that users can press --> <div class="save"> <img src="imag