TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-06-2010, 03:41 PM   #1 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default Working with cookies ARRG

Ok so i have 2 pages one where the user can view it as a slide show and one where they can view it as a list using <table>

So i come to the idea of using the list incase the user does not have high speed net and thought it might take them a while to actually load the slide... so they have the option just to view it as a list. So upon this i was thinking to myself well if they want to view it as a list then i need it to go back to the list when they re-visit the site rather than going to the default page (where the slide show is) so i thought cookies would do the trick!

So here i have it

index.php containing:
PHP Code:
<?php
if(isset($_COOKIE['viewinglist']))
    
header'Location: indexlist.php' ) ;
else

?>
If there is a cookie there then redirect them to indexlist.

So now in indexlist.php i got:
PHP Code:
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths 60 60 24 60 time(); 
$value "Viewing as list";
setcookie('viewinglist'$value$inTwoMonths); 
?> 
We are setting the cookie so they have entered the page so when it goes to index it will read this cookie to show they should be on indexlist.php and it will redirect them to there.

Ok... so now, the user has just clicked the view as slide show!
this will take the user to:
PHP Code:
includes/viewasslide.php 
which contains code to "delete" the cookie or if you like "set it to a date before the now time...
PHP Code:
<?php
//Killing the cookie:
$cookie_name="viewinglist";

//here we assign a "0" value to the cookie, i.e. disabling the cookie:
$cookie_value="";

//When deleting a cookie you should assure that the expiration date is in the past,
//to trigger the removal mechanism in your browser.
$cookie_expire=time()-60;

$cookie_domain="";
setcookie($cookie_name$cookie_value$cookie_expire"/"$cookie_domain,0);

//re-direct to login screen (or any other you like):
header"Location:../index.php");
exit;
?>
Now the problem is when i click this link and run this script its not actually deleting it or resetting the value to a previous time and keeps taking me back to indexlist.php where really it should be on index.php.

I cant see myself where its wrong but it obviously is. Could someone point out where im wrong? Thanks
Tim Dobson is offline  
Reply With Quote
Old 04-06-2010, 06:03 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Just out of curiousity, why all the redirects? Without being completely familiar with the logic operating here, it seems like you're sending the user all over the board just to define a setting for the current page.

Use sessions. Set them in the head of the script, and use the values of these to determine how the rest of the script will display its content.
delayedinsanity is offline  
Reply With Quote
Old 04-06-2010, 06:46 PM   #3 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

No they only get sent to 2 places. Indexlist.php when they click on view as list and index.php when they click on view as slide.
Tim Dobson is offline  
Reply With Quote
Old 04-06-2010, 07:37 PM   #4 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

Well taking a look at the sessions. This is not what i want, this is temporay data, i need it as perminant data so if the users closes the browser and returns say 5 days later when he visits he will be back at the page he was viewing 5 days previous.
Tim Dobson is offline  
Reply With Quote
Old 04-06-2010, 08:59 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

That's understandable - but I'm still not quite following the logic of your redirects, and this could be as simple as my thought process not coinciding with yours on how to do such things.

1. Check for existence of cookie, 'yoursite_view' and retrieve value of said cookie
- set a cookie if none exists and we need to
- assign value of cookie or result of user interaction to a local var we can use later
2. Use value of local var to determine what page style we're looking for
3. Load that page style inline, without redirecting.

The idea here is to do everything we need to encapsulated inside the single page that's going to be presenting the results. Include your functions from a remote file if you like, but keep it silent so that all the user knows is that they're getting the view that they want, on the page that they were visiting.
delayedinsanity is offline  
Reply With Quote
Old 04-07-2010, 09:30 PM   #6 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

Ok i will try explain it more to show you what im trying to accomplish. If i give you the url to my site it may be a big more clear (http://www.tentun.co.uk/sb0t/)

You can see on the index page there is a slideshow, this will allow users to view each template on the site or as more view each preview and have a download link on each slide.

Now i have the problem where some people may not be able to have the slide show, or it takes a long time for there browser to load it due to maybe slow connection? Upon thinking this i thought welll let them have the option to view it as a list in a table.

Now that slide show is on another page just so it wouldent have so much jibberish in the index... so i used the include.

My original idea was just to have it load a different include using the if statement if the user choose this option, but i got a bit stuck doin that like i got a bit stuck doing this lol.

So i created another page with the list on it, almost exactly the same as the index but without the slide show, so i created a url on the top to "view as list" which would take them to the list page... on the list page there is a link "view as show" which would take them back to the main index. So really if they choose the "show as list" i was trying to just set a cookie so when they return to the site in the future rather than taking them to the index it should take them to the list, or if they clicked another link on the site and then clicked the link "Template directory" if they were originaly viewing it as list rather than take them to the index like it does by default it would take them to the "list" page.

This was the idea behinde just using cookies, there is an if statement and i used it to see if there was a cookie there and if there is a cookie there it would take them to the list page rather than the index, and the "view as slide" link would or should make that cookie invalid, which is where i am getting stuck because i dont know how to configure it correct. My guess correct me if im wrong is because maybe i need to use the value of the cookie? but again i dont know how to go about this and use an if statement to determine which page they should be at.
Tim Dobson is offline  
Reply With Quote
Old 04-07-2010, 09:30 PM   #7 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

jesus i just wrote an essay haha sorry about it being so long just trying to shed more light on what im trying to do :P
Tim Dobson is offline  
Reply With Quote
Old 04-08-2010, 01:31 AM   #8 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

No more redirects! :) Tell me if the following makes sense:

php Code:
// Set default values
$default_view  = 'gallery';
$cid           = 'tentun_view';
$expire        = strtotime( '+2 Months' );

// Look for the cookie, and validate its value or set our view to the default
$view = ( isset( $_COOKIE[$cid] ) && in_array( $_COOKIE[$cid], array( 'gallery', 'list' ) ) ) ? $_COOKIE[$cid] : $default_view;

// Allow the view to be short circuited via GET
if ( isset( $_GET['view'] ) )
    $view = ( $_GET['view'] != 'list' ) ? $default_view : 'list';

// Remember the desired view
// You could remove the if statement and set it on every page view to constantly push the expire forward
if ( ! isset( $_COOKIE[$cid] ) || $_COOKIE[$cid] != $view )
    setcookie( $cid, $view, $expire, '/', '.tentun.co.uk' );

echo $header; // This stuff is up to you of course

// Set PATH and include a file named after your view
require_once( PATH . "{$view}.php" );

echo $footer;

Last edited by delayedinsanity : 04-08-2010 at 03:20 PM.
delayedinsanity is offline  
Reply With Quote
Old 10-18-2012, 12:57 PM   #9 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
dashixiong is offline  
Reply With Quote
Old 10-22-2012, 08:51 AM   #10 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Old 10-22-2012, 08:59 AM   #11 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Old 01-29-2013, 12:17 PM   #12 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Organizers said Coach Outlet Online was opportune because the battle’s 150-year anniversary is in December, and Fredericksburg Coach Factory Outlet has been preparing to mark the sesquicentennial. in the new agreement is that Coach Outlet Online revolutionary councils from 14 Syrian provinces now each have a representative, though not all live Coach Online Outlet in Syria. The hope is that will bind the coalition to those inside the country. Perhaps Coach Bags Outlet the most important body the new group is expected to form is a Revolutionary Military Council Coach Factory Online to oversee the splintered fighting organizations and to funnel both lethal and nonlethal Coach Factory Outlet military aid to the rebels. It should unite units of the Free Syrian Army, various militias Coach Outlet Store Online and brigades in each city and large groups of defectors. Before the ink was even dry on the Coach Outlet Store final draft, negotiators hoped that it would bring them the antiaircraft missiles they crave to Coach Factory Stores take on the Syrian Air Force. The United States and Britain have offered only Coach Handbags Outlet nonmilitary aid to the uprising. A similar attempt by the Syrian National Council to Coach Factory Store supervise the military never jelled. Organizers said funding was too haphazard. Eventually foreign Coach Factory Online governments like Qatar and Saudi Arabia, which are financing and arming the rebels, found Coach Factory Online their own favorite factions to deal with. Foreign leaders notably including Secretary of State Coach Outlet Hillary Rodham Clinton urged this unification largely so they could coordinate their Coach Factory Outlet efforts and aid through a group of technocrats. Once it receives international recognition, the Coach Outlet Store Online coalition is supposed to establish a temporary Coach Outlet Online military never jelled.
dashixiong is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remember me login w/ cookies Killswitch General 5 12-24-2009 10:54 PM
Wamp working, but what next? Help! DotNetTim Absolute Beginners 3 02-07-2009 10:05 AM
Mod Rewrite only partially working Gareth General 6 12-24-2008 06:08 PM
function that returns an array -- why not working? Dave Absolute Beginners 3 08-13-2008 05:01 PM
working with Iframes in php JMHein Absolute Beginners 3 05-17-2008 03:40 PM


All times are GMT. The time now is 03:21 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design