Jump to content

Recommended Posts

on my site you login to mysite.co.uk then you can go to forum.mysite.co.uk but when Firefox goes there is shows a problem page I coded

<?
session_start(); // Session Start
include 'db.php'; // Connect to DB
$email = $_COOKIE['email']; 
$password = $_COOKIE['password'];
if((!$email) || (!$password)){ 
echo "<html><head><link rel='stylesheet' href='default.css'><title>PROBLEMS!</title></head><body>Please enter ALL of the information! <br /></body></html>"; // THIS IS THE PROBLEM PAGE IT SHOWS!
include 'http://www.koggdesigns.co.uk/index.php'; 
exit(); 
}else{

$sql = mysql_query("SELECT * FROM users WHERE email='$email' AND password='$password'"); 
$login_check = mysql_num_rows($sql); 

if($login_check == 0){
echo"<html><head><link rel='stylesheet' href='default.css'><title>PROBLEMS!</title></head><body>There were errors logging in. <a href=http://www.koggdesigns.co.uk/index.phphttp://www.koggdesigns.co.uk/index.php>Try again!</a></body></html>";
exit();
}else{ 
// page here
}
?>

 

the page before starts like this:

session_start(); // Session Start 
include 'db.php'; // Connect to DB 
$email = $_POST['email'];  
$password = $_POST['password'];
setcookie(email, $email);
setcookie(password, $password);

 

Why can't FF work this but IE can :-[

Link to comment
https://forums.phpfreaks.com/topic/37937-solved-firefox-and-cookies/
Share on other sites

if you want your site cookies to work across subdomains you need to setup the cookie completely, the following should do:

setcookie('email' $email, time+3600, '/', '.mysite.com')

 

That will tell the browser to set a cookie called email with the value of $email, expire the cookie after an hour. Allow the cookie to be accessed site-wide and be used in sub-domains.

 

Also make sure the browser is accepting cookies - very important that.

 

Also session_start(); is not needed in your code as you appear to not be using sessions. Only cookies - which are not sessions.

Current Cookies

// first login page:
setcookie(email, $email, time+3600, '/', '.koggdesigns.co.uk');
setcookie(password, $password, time+3600, '/', '.koggdesigns.co.uk');

// ALL other pages mysite.co.uk/pages.php AND subdomain.mysite.co.uk/pages.php
$email = $_COOKIE['email']; 
$password = $_COOKIE['password'];

 

Current Cookies

// first login page:
setcookie(email, $email, time+3600, '/', '.koggdesigns.co.uk');
setcookie(password, $password, time+3600, '/', '.koggdesigns.co.uk');

// ALL other pages mysite.co.uk/pages.php AND subdomain.mysite.co.uk/pages.php
$email = $_COOKIE['email']; 
$password = $_COOKIE['password'];

 

EDITED

 

Do you still have a problem with the code?

 

I notice in your code when you set the cookie you don't wrap the cookie name (first parameter for set_cookie) in quotes. You should wrap all strings in quotes unless you are using a constant. If you are using constants then they should be in uppercase (MYCONST).

 

Also did a slight boobo with the code it should be this:

// first login page:
setcookie('email', $email, time()+3600, '/', '.koggdesigns.co.uk');
setcookie('password', $password, time()+3600, '/', '.koggdesigns.co.uk');

I forgot to add the () after time. So the cookies where invalid and thus it didn't work.

Yes you can. Note the number must in secound. So 1 hour = 3600. if you want the cookie to expire after a week for example, then do this:

 

time()+3600*24*7

 

3600 (1 hour) x 24 (24 hours = 1 day). Then times that by 7 to get the seconds in a week (7 days in a week). Its just basic maths :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.