Jump to content

Recommended Posts

Hi there,

 

I am passing an id through a session variable which is working succesfully in all Mac browsers and Firefox on Windows. However the session will not pass through when using IE (6 or 7).

 

I am a relatively inexperienced php'er and may be making basic errors. Apologies for the messy code:

 

this code is where the session (page_id) is set on the page called links.php

 

if ($tid == NULL) { //if its new

 

$time = time();

$query = "INSERT INTO fp_users (timestamp) VALUE ('$time')";

$result = @mysql_query ($query) OR DIE(mysql_error()); //run the query

$tid = @mysql_insert_id();

 

if (mysql_affected_rows() == 1) { //record has been added ok.

$query = "INSERT INTO fp_links (page_id, link1, link2, link3) VALUES ('$tid', '$l1', '$l2', '$l3')";

$result = @mysql_query ($query); //run last query

 

if (mysql_affected_rows() == 1) {//if query ran ok.

 

//everything done so return to template

 

 

$_SESSION['page_id'] = $tid;

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/new.php";

header("Location: $url");

exit;

 

}

}

}

 

then onto new.php where the following code stores the session in the variable $tid

 

$tid = $_SESSION['page_id'];

 

fairly straight forward. From here the user can then go back to make adjustments to links.php where this code(which on the page comes above the first snippet i wrote in this post) checks for the active session and defines is on this page as $tid.

 

session_start();

 

 

if(isset($_SESSION['page_id'])) { //if there is a page id

$tid =  $_SESSION['page_id'];

 

} else {

$tid = NULL;

//print "not set";

}

 

Again quite simple. The print "not set"; is from where i've been testing.

 

To put this in context: new.php calls in links.php through thickbox (http://jquery.com/demo/thickbox/) and then the user enters content into the database through links.php which then closes on submit and these results are displayed on new.php.

I have confirmed through some testing that that the session is passed the first time back from links.php to new.php. But when you go back from new.php to links.php the session is lost.

 

This is my first major php project and I realise now (toward the end of it) that there are more efficient ways of coding this project but unfortuntely I am stuck with this now.

 

Thanks in advance for any help.

 

Gareth.

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/51761-session-not-passing-in-ie/
Share on other sites

Hi,

 

I have session_start() at the top on both pages. If you want to look at the pages live they are available at http://gareth.routeb.com/expressions/new.php (un:test / pw:test).  The problem with sessions is occuring with any of the 6 available options but i am doing my testing on the links section which is number 6.

 

The script is long so I have highlighted the relevant parts:

 

This is new.php . I have not included the html which would display the variables defined in this script.

 

<?php

 

session_start();

 

 

 

if(isset($_SESSION['start'])){

$active = $_SESSION['start'];

 

} else {

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/newCheck.php";

header("Location: $url");

exit;

}

 

 

 

$tid = $_SESSION['page_id'];

$cp_id1 = $_SESSION['cp_id1'];

$cp_id2 = $_SESSION['cp_id2'];

$cp_id3 = $_SESSION['cp_id3'];

$cp_id4 = $_SESSION['cp_id4'];

$cp_id5 = $_SESSION['cp_id5'];

 

 

require ('../mysql_connect.php'); //Connect to DB

include ('includes/checkprogress.php');

 

$errorBox = 'hidden';

$errorColour = '';

 

/******check for errors and id from cp1(title)****/

if (empty($_SESSION['errors'])) {

 

if ( ($_SESSION['page_id']) && ($cp_id1 == 1) ) {

 

$query = "SELECT text, colour, font FROM fp_header WHERE page_id='$tid'";

$result = mysql_query ($query);

$row = mysql_fetch_array ($result, MYSQL_ASSOC);

 

$title = $row['text'];

$titleFont = $row['font'];

$titleColour = $row['colour'];

 

 

} else {

 

$title = "Your Title Here";//for title

$titleFont = "helvetica.swf";

$titleColour = '000000';

}

 

} else {

 

$errorBox = 'visible';

$errorColour = 'background:#000;';

$title = 'There was an error';

$titleFont = "stencil.swf";

$titleColour = '000000';

$errors = $_SESSION['errors'];

}

 

/******check for errors and id from cp2(image)****/

if (empty($_SESSION['errors'])) {

 

if ( ($_SESSION['page_id']) && ($cp_id2 == 2) ) {

 

 

$query2 = "SELECT img_src FROM fp_header WHERE page_id='$tid'";

$result2 = mysql_query ($query2);

$imageName = mysql_result($result2, 0);

$imageloc = "includes/ImageUploader/main_images/" . $imageName;

 

} else {

 

 

$imageloc = 'images/test_img.jpg';//for main image

 

}

 

} else {

 

$errors = $_SESSION['errors'];//for main image

$imageloc = 'images/test_img.jpg';//for main image

 

}

 

/******check for errors and id from cp3(header)****/

if (empty($_SESSION['errors'])) {

 

if ( ($_SESSION['page_id']) && ($cp_id3 == 3) ) {

 

$query2 = "SELECT bg_src FROM fp_header WHERE page_id='$tid'";

$result2 = mysql_query($query2);

$bg_img = mysql_result($result2, 0);

$bg_img_loc = "gfx/header/" . $bg_img;

 

 

} else {

 

 

$bg_img_loc = '';

 

}

 

} else {

 

$errors = $_SESSION['errors'];

$bg_img_loc = '';

 

}

 

/******check for errors and id from cp4(maintext)****/

if (empty($_SESSION['main_errors'])) {

 

if ( ($_SESSION['page_id']) && ($cp_id4 == 4) ) {

 

$query = "SELECT text, colour, font, align FROM fp_maintext WHERE page_id='$tid'";

$result = mysql_query ($query);

$row = mysql_fetch_array ($result, MYSQL_ASSOC);

 

$mtxt = $row['text'];

$mtxt_f = $row['font'];

$mtxt_c = $row['colour'];

$mtxt_a = $row['align'];

 

} else {

 

$mtxt = "Your Main Text Here";//for title

$mtxt_f = "Arial, Helvetica, sans-serif";

}

 

} else {

$mtxt = $row['text'];

$mtxt_f = $row['font'];

$mtxt_c = $row['colour'];

$mtxt_a = $row['align'];

$errorBox = 'visible';

$errorColour = 'background:#000;';

$errors = $_SESSION['main_errors'];

 

}

 

//for gallery_images

if ($_SESSION['page_id']) {

 

$query = "SELECT * FROM fp_images WHERE (page_id='$tid')";

$result = mysql_query($query) OR DIE(mysql_error());

while ($row = mysql_fetch_assoc($result)) {

$dirLoc = "includes/ImageUploader/gallery_images/thumbs/";

 

$img1 = $dirLoc . $row["img1"];

    $img2 = $dirLoc . $row["img2"];

    $img3 = $dirLoc . $row["img3"];

    $img4 = $dirLoc . $row["img4"];

$img5 = $dirLoc . $row["img5"];

$img6 = $dirLoc . $row["img6"];

$img7 = $dirLoc . $row["img7"];

$img8 = $dirLoc . $row["img8"];

$img9 = $dirLoc . $row["img9"];

 

}

 

$dirLoc2 = "includes/ImageUploader/gallery_images/deleteimage.php?id=";

 

}

 

//checks for links

 

if ( ($_SESSION['page_id']) && ($cp_id5 == 5) ) {

 

$query = "SELECT link1, link2, link3 FROM fp_links WHERE page_id='$tid'";

$result = mysql_query ($query);

$row = mysql_fetch_array ($result, MYSQL_ASSOC);

 

$l1 = $row['link1'];

$l2 = $row['link2'];

$l3 = $row['link3'];

 

} else {

 

$l1 = "Your links here";

$l2 = "Your links here";

$l3 = "Your links here";

}

 

 

?>

 

 

The user would then click on any link but i am testing with the image link (the number '6') which goes to link.php.

 

 

<?php #links.php - insert or edit links.

 

session_start();

 

 

if(!empty($_SESSION['page_id'])) { //if there is a page id

$tid =  $_SESSION['page_id'];

$_SESSION['cp_id5'] = 5;

} else {

$tid = NULL;

//print "not set";

$_SESSION['cp_id5'] = 5;

}

 

$_SESSION['errors']  = array();//Clear header errors array

$_SESSION['main_errors'] = array();//Clear main text errors array

$_SESSION['links_errors'] = array();//Clear links error array

 

 

 

require_once ('../mysql_connect.php'); //Connect to DB

 

 

 

if(isset($_POST['submitted'])) { //If 'submitted' found then handle form

 

if (!empty($_POST['link1'])) {

 

$l1 = $_POST['link1'];

$l1 = str_replace("http://", "", $l1);

 

 

} else {

 

$l1 = '';

 

}

 

if (!empty($_POST['link2'])) {

 

$l2 = escape_data($_POST['link2']);

$l2 = str_replace("http://", "", $l2);

 

 

} else {

 

$l2 = '';

 

}

 

if (!empty($_POST['link3'])) {

 

$l3 = escape_data($_POST['link3']);

$l3 = str_replace("http://", "", $l3);

 

 

} else {

 

$l3 = '';

 

}

 

/*******NEW PROJECT - no id *******/

if ($tid == NULL) { //if its new

 

$time = time();

$query = "INSERT INTO fp_users (timestamp) VALUE ('$time')";

$result = @mysql_query ($query) OR DIE(mysql_error()); //run the query

$tid = @mysql_insert_id();

 

if (mysql_affected_rows() == 1) { //record has been added ok.

$query = "INSERT INTO fp_links (page_id, link1, link2, link3) VALUES ('$tid', '$l1', '$l2', '$l3')";

$result = @mysql_query ($query); //run last query

 

if (mysql_affected_rows() == 1) {//if query ran ok.

 

//everything done so return to template

 

$_SESSION['start'] = 1;

$_SESSION['page_id'] = $tid;

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/new.php";

header("Location: $url");

exit;

 

} else {

 

$query = "DELETE FROM fp_users WHERE page_id='$tid'";

@mysql_query($query); //run query

 

echo '<p>Sorry, there was a problem choosing your font, HAVE ANOTHER GO........</p>';

echo '<p>'.mysql_error() .'<br /><br />This error relates to this query: ' .$query. '</font></p>'; //debugging

}

 

} else {

 

echo '<p>Sorry, there was a problem entering your Page Title, HAVE ANOTHER GO........</p>';

echo '<p>'.mysql_error() .'<br /><br />This error relates to this query: ' .$query. '</font></p>'; //debugging

 

}

 

} else if ($tid > 0) {

 

$query = "SELECT * FROM fp_links WHERE (page_id='$tid')";

$result = mysql_query ($query) OR DIE(mysql_error());

$row = mysql_fetch_row($result);

 

if ($row[0]) {

 

$query = "UPDATE fp_links SET link1='$l1', link2='$l2', link3='$l3' WHERE page_id=$tid";

$result = mysql_query ($query) OR DIE(mysql_error());

 

if ($result) {

 

$_SESSION['start'] = 1;

$_SESSION['page_id'] = $tid;

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/new.php";

header("Location: $url");

exit;

} else {

$message[] = '<font color="red">There was a problem with your entry, please try again.</font>';

$_SESSION['errors'] = $message;

$_SESSION['start'] = 1;

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/new.php";

header("Location: $url");

exit;

 

}

} else {

 

$query = "INSERT INTO fp_links (page_id, link1, link2, link3) VALUES ('$tid', '$l1', '$l2', '$l3')";

$result = @mysql_query ($query) OR DIE(mysql_error());;

 

if (mysql_affected_rows() == 1) {

 

$_SESSION['page_id'] = $tid;

$_SESSION['start'] = 1;

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/new.php";

header("Location: $url");

exit;

 

} else {

echo '<p>Sorry, there was a problem entering that link HAVE ANOTHER GO........</p>';

echo '<p>'.mysql_error() .'<br /><br />This error relates to this query: ' .$query. '</font></p>'; //debugging

 

}

 

}

 

} else {  //if one of the initial data test failed.

 

$_SESSION['errors'] = $message;

$_SESSION['start'] = 1;

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . '/expressions';

$url .= "/new.php";

header("Location: $url");

 

 

}

 

 

 

 

}//end of submitted conditional

include ("select_functions.php");

?>

 

<form action="includes/links.php" method="post">

 

Link1:

<input type="text" name="link1" size="40" maxlength="100" value="<?=$link1;?>" /><br /><br />

Link2:

<input type="text" name="link2" size="40" maxlength="100" value="<?=$link2;?>" /><br /><br />

Link3:

<input type="text" name="link3" size="40" maxlength="100" value="<?=$link3;?>" /><br /><br />

 

 

 

 

<input type="hidden" name="submitted" value="TRUE" />

<div align="center"><input type="submit" name="submit" value="Submit" /></div>

 

</form>

 

 

<?php

mysql_close();

?>

 

 

 

Thanks for looking at this for me.

 

Gareth

 

 

 

 

 

 

 

 

From my testing, the session cookie is set and accepted by IE from new.php.  But the cookie is not sent to links.php.

 

In firefox it works, and the session cookie goes to links.php

 

A possible workaround might be to manually send the session ID to links.php.  I'm not sure why it's happening like that though..

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.