473,788 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cookie

What's the best I can do to solve my trouble :

I got a simple page index-tmp who include a code snippet who test if a cookie
exist and if yes redirect to the user account page but the trouble
is when I didn't 've a cookie the page still redirect to the user account page.

here is the following code :

<?
$cookie = $_COOKIE["free-nickname"];
if (!cookie == null) {
echo '<script langage = "javascript ">';
echo " document.locati on.href = 'index_utilisat eur.php';";
echo '</script>;';
}
else {
echo '<script langage = "javascript ">';
echo " document.locati on.href = 'index.php';";
echo '</script>;';
}
?>

thx in advance
Jul 17 '05 #1
6 1881
Your line :
if (!cookie == null) {

should read:
if (!$cookie == null)
(You missed the $ before the cookie variable name)

Thanks!

Jul 17 '05 #2
Damn I'm stupid thx Kartic :)

"Kartic" <ka************ ******@gmail.co m> wrote:
Your line :
if (!cookie == null) {

should read:
if (!$cookie == null)
(You missed the $ before the cookie variable name)

Thanks!

Jul 17 '05 #3
Alexandre wrote:
What's the best I can do to solve my trouble :

I got a simple page index-tmp who include a code snippet who test if a cookie
exist and if yes redirect to the user account page but the trouble
is when I didn't 've a cookie the page still redirect to the user account
page.

here is the following code :

<?
$cookie = $_COOKIE["free-nickname"];
if (!cookie == null) {
echo '<script langage = "javascript ">';
echo " document.locati on.href = 'index_utilisat eur.php';";
echo '</script>;';
}
else {
echo '<script langage = "javascript ">';
echo " document.locati on.href = 'index.php';";
echo '</script>;';
}
?>

thx in advance


I think "if ($cookie != null)" might work better.

Don't use Javascript to redirect visitors -- HTTP redirects are much safer.
I suggest you make index.php your default home page and put this script at
the top of the file:

<?php

$cookie = $_COOKIE["free-nickname"];
if ($cookie != null) {
header("HTTP/1.1 302 Found");
header("Locatio n: http://www.yourdomain. com/index_utilisate ur.php");
exit;
}
else {
header("Vary: Cookie");
}

....
?>

P.S. To include javascript in an HTML file, use <SCRIPT
type="text/javascript">, not <SCRIPT lang(u)age="jav ascript">

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #4
.oO(Alexandre)
I got a simple page index-tmp who include a code snippet who test if a cookie
exist and if yes redirect to the user account page [...]


Why are you using unreliable client-side redirection? Do it properly and
use a Location header with an absolute URL:

header('Locatio n: http://www.example.com/foo');

Micha
Jul 17 '05 #5
With the Location header you can make sure that all your visitors will
be redirected to the page you want to redirect them to. Think of
lynx/links users who do not use a javascript enabled browser. Also,
please note that the header() must go before any output is made on the
page.

Good luck
Clau

Jul 17 '05 #6
great thx =)

"Kartic" <ka************ ******@gmail.co m> wrote:
Your line :
if (!cookie == null) {

should read:
if (!$cookie == null)
(You missed the $ before the cookie variable name)

Thanks!

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5296
by: Shannon Jacobs | last post by:
I'm doing some trivial surveys, and I want to know if the same user answers twice. Can't really know that, but at least I thought I could check for the same browser/computer combination by using a cookie. Here is the code I have now. In the header, I have the following: <SCRIPT language="JavaScript"> var cookieStatus; if (document.cookie.length > 0) { cookieStatus = 'Cookie exists with value ' + document.cookie; } else {
12
18017
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the home page during their time using the browser. However, if the user closes the browser, then reopens, the pop-up should appear again. (you may have guessed that this will be used for public access pc's.) I want to try as best I can to catch...
5
3314
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the document.cookie variable combine all cookie key=value pairs? All of the examples I've seen discuss referencing a specific cookie. I don't see how this is done. Cookies are usually named by the domain. If I want to reference a specific cookie, do I...
4
3822
by: socialism001 | last post by:
I'm trying to store a value in a cookie but its not working. Can anyone see what I might be doing wrong. Thanks, Chris ~~~~~~~~~~~~~~~~~~ <script language="javascript"> if(document.cookie.indexOf("beenHere1=true")!=-1) else
9
4505
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored in a cookie and a small bullit shown in front of the hyperlink, so when I reload the page I can immediately see which hyperlinks I already visited that day.
3
11124
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
1
6718
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to simply pass the values in a cookie to the querystring that would be even easier, but from what I've been able to tell, cookie values can't be passed to a querystring. I'm sure the answer will help alot of others who are using this script, and would...
6
2702
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My problem is how do I handle the "path" parameter in cookie. First, the sequence start at http://www.testServer1.com/TestApp/page1.htm, and a cookie is set at
2
2854
by: kelly.pearson | last post by:
Is this a bug? I am trying to write a cookie that can be accessed by various .Net applications on our domain. However, whenever I add the domain property to the cookie, no errors get thrown but the cookie doesn't get written. I am trying this from my localhost using vs2003, .net framework 1.1, windows xp prof. Sample code I am testing with is below. Public Class WebForm1 Inherits System.Web.UI.Page
5
3164
by: cbhoem | last post by:
Hi - I am trying my hand at python cookies. I'm confused about a few things though. Do the python cookies get written to a cookies text file? I have simple code below -- I see the cookie in my HTTP header but do not get anything in the cookie text file. I'm working on linux. print "Content-type: text/html" cookie = Cookie.SimpleCookie()
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.