473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SESSION lost when submitting form

73
Hello,

I've been testing my site and have ran into a problem, I have a page in which members can make a portfolio, giving other members the ability to rate it, recommend it, favourite it etc.

All my pages the pages have the same structure, all include the same files such as session.php etc. The session works fine until they submit a form, when the form is submitted it logs them out, and as guests can not use these functions it shows them a message saying they need an account to do this.

I'm not exactly sure where to start looking for this, I'd post an example of my code but I don't know what to post and can't really post the whole thing. If anybody needs me to post anything specific up I'll be happy to.

Thanks,
Jeigh
Aug 25 '07 #1
16 7662
Atli
5,058 Expert 4TB
If the sessions are working everywhere else, it is most likely that you simply overlooked something somewhere in your form process code.

Do you use the function session_unset() anywhere in you code?

You could try searching for all instances of the word 'session' in you code and see if there is something that shouldn't be there.
Aug 25 '07 #2
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Try adding this to the top of each page:
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
  3. // Debug
  4. echo session_id();
  5.  
The value that it outputs should be the same for each page. If it is different, you need to check your session cookie settings in your php.ini file.
Aug 26 '07 #3
Jeigh
73
Sorry for the late reply, I used that and it showed up properly on every page except after I submitted a form on the profile page, which is when it logged me out so the session was lost. There's absolutely nothing that I can see that would get rid of the session, the form is very basic. So slightly confused on this one :P
Aug 31 '07 #4
ak1dnar
1,584 Expert 1GB
Better to post the codes here, which the occurs the problem. and then we'll be able to look at it closely.
Aug 31 '07 #5
Jeigh
73
I'm not exactly sure where the problem is occuring but this is the form:

Expand|Select|Wrap|Line Numbers
  1. echo "<form action=\"$PHP_SELF?user=$fuser\" method=\"post\">
  2. <input type=\"hidden\" name=\"type\" value=\"$type\" />
  3. <input type=\"hidden\" name=\"fuser\" value=\"$fuser\" />
  4. <input type=\"hidden\" name=\"display\" value=\"$display\" />
  5. <input type=\"hidden\" name=\"rate2\" value=\"$rate\" />
  6. <input type=\"hidden\" name=\"rec\" value=\"$rec\" />
  7. <input type=\"hidden\" name=\"style\" value=\"$style\" />
  8. <input type=\"hidden\" name=\"name\" value=\"$name\" />
  9. <input type=\"hidden\" name=\"favourite\" value=\"1\" />
  10. <input type=\"image\" src=\"images/favourite.gif\" name=\"submit\" value=\"Favourite\" />
  11. </form>";
  12.  
And to process it:

Expand|Select|Wrap|Line Numbers
  1. if($_POST['favourite']){
  2.  
  3. $fdate = date('Y-m-d H:i:s', time());
  4. $ffuser = $_POST['fuser'];
  5. $fdisplay = $_POST['display'];
  6. $frate = $_POST['rate2'];
  7. $frec = $_POST['rec'];
  8. $fstyle = $_POST['style'];
  9. $fname = $_POST['name'];
  10.  
  11. $count = "SELECT COUNT(*) FROM favourites WHERE username='$fusername' AND fuser='$ffuser'";
  12. $countq = mysql_query($count);
  13.  
  14. $countq2 = mysql_fetch_row($countq);
  15.  
  16. $countq3 = $countq2[0];
  17.  
  18. if($countq3 >= 1){
  19. echo "You already have this profile in your favourites.";
  20. }
  21. else
  22. {
  23. $query = "INSERT INTO favourites VALUES('', '$fusername', '$fdate', 'profile', 'T', '$ffuser', '$fdisplay', '', '', '', '', '', '', '', '', '', '$frate', '$frec', '$fstyle', '$fname')";
  24. mysql_query($query);
  25.  
  26. echo "This profile has been sucessfully added to your favourites.";
  27. }
  28. }
  29.  
Aug 31 '07 #6
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Where do you check to see if the User is logged in?
Aug 31 '07 #7
ak1dnar
1,584 Expert 1GB
I didn't see anything related to session in the coding. If you already created this On a previous page try to print the session ids in each and every page.
If there is mismatch on the session id then we can find it.
Aug 31 '07 #8
Are you sending output to the browser (Other then headers) before you trigger a
[PHP]session_start();[/PHP]
Aug 31 '07 #9
ak1dnar
1,584 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. session_start();
Ah Is it not there?
Aug 31 '07 #10
Jeigh
73
I have session_start(); right at the top and nothing is sent before that, but I just found somthing odd. It's actually happening just on refreshing the page, not submitting a form. But if I'm viewing my own profile which would be:

/profile.php?user=me

I can refresh without losing the session however ever if it's someone elses which would be:

/profile.php?user=someoneelse

It loses the sesion once it's refreshed.
Sep 2 '07 #11
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Let's have a look at profile.php.
Sep 2 '07 #12
Jeigh
73
Sorry for the late reply again, here's some of profile.php, it's very long so I'll take out a lot of the irrelevant code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. session_start();
  4. include('include/session.php');
  5.  
  6. $fusername = $_SESSION['username'];
  7. $sendername = $_SESSION['username'];
  8.  
  9. /* Requested Username error checking */
  10. $req_user = trim($_GET['user']);
  11. if(!$req_user || strlen($req_user) == 0 ||
  12.    !eregi("^([0-9a-z])+$", $req_user) ||
  13.    !$database->usernameTaken($req_user)){
  14.    die("Username not registered");
  15. }
  16.  
  17. /* Display requested user information */
  18. $req_user_info = $database->getUserInfo($req_user);
  19.  
  20. include('headeruserinfo.php');
  21. include('navigation.php');
  22. include('content.php');
  23.  
  24. ?>
  25. <table cellspacing="10" cellpadding="3" class="profile">
  26. <tr>
  27. <td class="profile">
  28. <?
  29.  
  30.  
  31.  
  32.  
  33.  
  34. /* Logged in user viewing own account */
  35. if(strcmp($session->username,$req_user) == 0){
  36.    echo "<div class=\"profilehead\" align=\"center\"><h3>My Profile</h3></div><img src=\"uploads/photo/" .$userphoto. "\" /><br /><a href=\"changephoto.php?user=$session->username\">Change Display Picture</a>";
  37. }
  38. /* Visitor not viewing own account */
  39. else{
  40.    echo "<div class=\"profilehead\" align=\"center\"><h3>";
  41.    echo $username;
  42.    echo "'s Profile</h3></div>";
  43.    echo "<img src=\"uploads/photo/";
  44.    echo $userphoto; 
  45.    echo " \" />";
  46. }
  47.  
  48. echo "</td>
  49. </tr>
  50. </table>";
  51.  
  52. /* If logged in user viewing own account, give link to edit */
  53. if(strcmp($session->username,$req_user) == 0){
  54.    echo "<br><a href=\"changeprofile.php\">Edit Profile</a><br>";
  55. }
  56.  
  57. /* Link back to main */
  58. echo "<br>Back To <a href=\"index.php\">Index</a><br />";
  59.  
  60. include('endcontent.php');
  61. include('footer.php');
  62.  
  63. ?>
  64.  
Sep 5 '07 #13
Figures you would stump them after they get a look at the code... What version of php are you using?

There can be serious mis configurations with the server as I am experiencing now... it is hard to convince people that php could be at fault butit happens... perhaps you should ask your server admin to make sure that your php installation is working as expected...

<?php

print(phpinfo());

?>

If it helps I am having serious session problems with php 5.2.5 right now... I can not pin it down to anything with code... it is specific to the server... and perhaps the php distribution itself... it is not a random problem... it is always reproducible in a location... but copy the code to a different folder / location... and your problem may be solved... hope this helps...
Jan 24 '08 #14
Make sure your not running php as a cgi ( opposed to an apache module)

and make sure you have no php.ini files over riding the default php.ini...

It took me forever to pinpoint the problem... but that's what broke sessions accross folders for me... hope this helps...
Jan 25 '08 #15
put this code on the top of the page where form is redirect after submit.

Expand|Select|Wrap|Line Numbers
  1.  session_start(); 
Jan 25 '08 #16
Atli
5,058 Expert 4TB
Hi Jeigh.

Could we see the 'include/session.php' file?
There doesn't seem to be any session code in the profile.php page itself, so the problem could be in the session.php file.

I would also recommend using <?php ?> tags rather than the <? ?> tags, just to avoid any possible problem if you ever switch servers. It's only 3 chars more, and can potentially save a lot of trouble ;)
Jan 25 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Perdit | last post by:
My 1st page calls a 2nd that uses same data from a database. What is the best way to get the data in the second: a new call to the database or passing array through session variable?? I seems...
7
by: Billy Jacobs | last post by:
I am having a problem with my session variable being set to Null for no apparent reason. I am declaring it like the following when the user logs in. dim objUserInfo as new clsUserInfo 'Set...
6
by: Tony G. | last post by:
Hi there, I have an APS 3 application, running on a Windows 2003 Web edition server - it is a very busy website, and when users are click on certain links (membership info), a new window i...
0
by: Michelle A. | last post by:
Can anyone offer help me out understand how to use Session State? I have a 4 page form (3 information entry the last page of the form is for data review before submitting). I would the user who...
0
by: Sebastian | last post by:
Hello, I've implemented an ASP.NET Application that is used by many people concurrently. Each user logs on using Forms Authentication (authentication against Active Directory). After logon...
3
by: Mike | last post by:
Hello: I was not able to find a regular ASP group, so I posted this here instead. I have a web app which is actually just ASP using VBScript as the server-side language, running on IIS6. ...
0
by: Aarchaic | last post by:
Hello i have problem my session variables seem to disapear as i go along i've created this code to ilustrate whats happening First off i just post 3 detials like a name a age and a favourite...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
1
by: Andy | last post by:
Hi Gang I need help. I have an ASP application that in a nutshell allows data entry on a main page. The problem is I'll have users that enter some data and save it. Then they'll enter some...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.