Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Get Cookie that create with PHP
Old 11-28-2007, 10:03 PM Get Cookie that create with PHP
Skilled Talker

Posts: 72
Trades: 0
Can we get cookie that create with PHP using Javascript? I have create $_COOKIE with PHP script and want call in html browser. If the cookie exist it will stay on the page but if not it will redirect to login page. Can someone help me?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
jaketmerah is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-28-2007, 11:02 PM Re: Get Cookie that create with PHP
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
I don't know very much about this, but this link I found on Google may be helpful to you: http://techpatterns.com/downloads/ja...pt_cookies.php
Nathand is offline
Reply With Quote
View Public Profile
 
Old 11-29-2007, 12:40 AM Re: Get Cookie that create with PHP
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Probably. As long as the javascript comes from the same domain - sometimes and folder - that created the cookie, there shouldn't be any problem.

While this might look like shameless self promotion, have a look at my blog, the one in my signature. You don't need to spend more than a minute or two looking at it in the browser ( just hit the [more] and [...] links ), but look into the javascript code. There's a lot that happens in the browser based on cookies. I'm not doing exactly what you want to - redirection based on the absence of a cookie - but I change properties on the current page based on cookies and their values when they exist. You'd just have to change the x.style.y = z to document.location = login-page.php or something like that.

That said, you probably don't want to build your authentication mechanism using cookies, because they're pretty easy to spoof.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 11-29-2007, 10:37 AM Re: Get Cookie that create with PHP
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
it's much simpler to redirect server side if the cookie doesn't exist.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-29-2007, 03:00 PM Re: Get Cookie that create with PHP
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
Quote:
That said, you probably don't want to build your authentication mechanism using cookies, because they're pretty easy to spoof.
What are you supposed to use then? Session variables?
Nathand is offline
Reply With Quote
View Public Profile
 
Old 11-29-2007, 03:11 PM Re: Get Cookie that create with PHP
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Certainly

if (!$_session["logged_in"]) {
header("login.php");
}

If you want a "Remember me" feature then you would have to use cookies, ensuring that you encode the username in the cookie (and don't call it user ) so the casual "cracker" (not hacker) has a bit more work to do to decipher it.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Get Cookie that create with PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23328 seconds with 12 queries