Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP session page refresh not working
    primarykey
    data
    text
    <p>I have a php page set up so that the user can click on a link to sign in and a pop up window (signin.php) pops up with sign in credentials. When they fill in the information and click the button to sign in the information is validated in signinfinal.php. When they sign in correctly I am trying to create a session. So when they sign in or close the popup window I want the main page they were on (index.php) to refresh and I want the 'Sign In | Register' links to change to 'Hi, (username)!' I set all of this as a a php variable named '$var' with some javascript in the variable.</p> <p>The weird thing is I am able to register and login on my computer on multiple browsers and the page refreshes and has my session stored correctly, but other users have reported that the session isn't working even after they refresh the page. This is a tricky problem and if someone can help me fix it I would appreciate it. </p> <p>Here is the code at the top of index.php...</p> <pre><code> &lt;?php // this starts the session session_start(); $var = ""; $varcontact = "&lt;a href='JavaScript:newPopup(\"http://www.yourfantasyfootballrealit.com/contact.php\");' class='three'&gt;Contact&lt;/a&gt;"; // echo variable from the session, we set this on our other page if ($_SESSION['userid'] == "") { $var = "&lt;a href='JavaScript:newPopup(\"http://www.yourfantasyfootballrealit.com/register.html\");' class='two'&gt;Register&lt;/a&gt; | &lt;a href='JavaScript:newPopup(\"http://www.yourfantasyfootballrealit.com/signin.php\");' class='two'&gt;Sign In&lt;/a&gt;"; } else { $var = "Hello, ".$_SESSION['userid'] ."! | " . "&lt;a href=\"http://www.yourfantasyfootballreality.com/logout.php\" class='two'&gt;Log Out&lt;/a&gt;"; } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script src="jquery-1.8.1.js"&gt;&lt;/script&gt; &lt;script src="jquery.easing-1.3.pack.js"&gt;&lt;/script&gt; &lt;script src="jquery-easing-compatibility.1.2.pack.js"&gt;&lt;/script&gt; &lt;script src="coda-slider.1.1.1.pack.js"&gt;&lt;/script&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;link rel="icon" href="http://www.indiana.edu/favicon.ico" /&gt; &lt;title&gt;YourFantasyFootballReality&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="mystyle.css" /&gt; &lt;script type="text/javascript"&gt; // Popup window code function newPopup(url) { popupWindow = window.open(url,'popUpWindow','height=450,width=600,left=10,top=10,resizable=no,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes') } function closeWin() { document.write("&lt;p&gt;This is 'myWindow'&lt;/p&gt;"); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;!--Login and Register links--&gt; &lt;div class="enter"&gt; &lt;?=$var?&gt; &lt;/div&gt; </code></pre> <p>Here is all of the code for signin.php</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt;&lt;title&gt;Sign In&lt;/title&gt;&lt;/head&gt; &lt;body onunload="window.opener.location.reload();"&gt; &lt;h1&gt;Sign In&lt;/h1&gt; &lt;form action="signinfinal.php" method="POST"&gt; &lt;table cellpadding="2" cellspacing="0" border="0"&gt; &lt;tr&gt; &lt;td width="130"&gt; User ID: &lt;/td&gt; &lt;td width="140"&gt; &lt;input name="UserID" type="text"&gt; &lt;/td&gt; &lt;td width="300" rowspan="7" valign="top"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt; Password: &lt;/td&gt; &lt;td&gt;&lt;input name="Password" type="password" size="15"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt;&lt;input type="submit" value="Sign In" name="action"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here is all of the code for signinfinal.php...</p> <pre><code>&lt;?php session_start(); //$id = $_SESSION['userid']; //$pw = $_SESSION['password']; //this connects to the database $con = mysql_connect("localhost","yourfan_jeengle","armyjoe"); mysql_select_db("yourfan3_demo", $con); //this is the info the user entered stored as variables $UserID = $_POST["UserID"]; $Password = $_POST["Password"]; $Action = $_POST["action"]; //this filters throught the variables to check against mysql injections $UserID = (filter_var($UserID, FILTER_SANITIZE_STRING)); $UserID = (filter_var($UserID, FILTER_SANITIZE_URL)); $Password = (filter_var($Password, FILTER_SANITIZE_STRING)); $Password = (filter_var($Password, FILTER_SANITIZE_URL)); //this is the variables that displays errors and correct instructions $errors = ""; //this gets the password from the userid entered by user $result = mysql_query("SELECT Password FROM Users WHERE User_ID = '$UserID'"); $row = mysql_fetch_array($result); $newresult = $row['Password']; if (strcmp($Action, "Sign In") == 0) { //this what happens when the user enters data for the first time and the info is wrong if (($newresult == $Password) &amp;&amp; (($UserID) &amp;&amp; ($Password))) { $greeting = "Welcome, " . $UserID; $_SESSION['userid'] = $UserID; $what="Log Out"; } else { $errors .= "&lt;li&gt; Incorrect Credentials!"; $what="Sign In"; } if ($errors) { $color = "#ffcccc"; $fontColor = "brown"; } } else { header("Location: http://www.yourfantasyfootballrealit.com/logout.php"); } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt;&lt;title&gt;Sign In&lt;/title&gt;&lt;/head&gt; &lt;body onunload="window.opener.location.reload();"&gt; &lt;h1&gt;Sign In&lt;/h1&gt; &lt;?=$greeting?&gt; &lt;form action="signinfinal.php" method="POST"&gt; &lt;table cellpadding="2" cellspacing="0" border="0"&gt; &lt;tr&gt; &lt;td width="130"&gt; User ID: &lt;/td&gt; &lt;td width="140"&gt; &lt;input name="UserID" type="text" value="&lt;?=$UserID?&gt;"&gt;&lt;/td&gt; &lt;td bgcolor="&lt;?=$color?&gt;" width="300" rowspan="7" valign="top"&gt;&lt;font color=&lt;?=$fontColor?&gt;&gt;&lt;ul&gt; &lt;?=$errors?&gt;&lt;/font&gt; &lt;/ul&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Password: &lt;/td&gt;&lt;td&gt;&lt;input name="Password" type="password" size="15" value="&lt;?=$Password?&gt;"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td colspan="2"&gt;&lt;input type="submit" value="&lt;?=$what?&gt;" name="action"&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is what is in logout.php if necessary...</p> <pre><code>&lt;?php session_start(); session_destroy(); ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Log Out&lt;/title&gt; &lt;script language="JavaScript"&gt; var time = null function move() { window.location = 'http://www.yourfantasyfootballreality.com' } &lt;/script&gt; &lt;!--&lt;meta http-equiv="REFRESH" content="1;url=http://www.yourfantasyfootballreality.com/"&gt;&lt;/HEAD&gt;--&gt; &lt;BODY&gt; &lt;body onload="timer=setTimeout('move()',000)"&gt; &lt;script language="javascript"&gt; &lt;!-- setTimeout("self.close();",0000) //--&gt; &lt;/script&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload