-
Posts
307 -
Joined
-
Last visited
Everything posted by TapeGun007
-
Why would this work fine in MSIE and not Chrome? The sessions are all set and read the same.
-
What do you mean exactly? ... the only time something changes... well for example, in my include file, all images and html links are the full domain http://www.mydomain.com, but in the main code, it's just a direct HREF link like login.php instead of http://www.mydomain.com/login.php. But I don't see how that affects anything.
-
Yes, she does have cookies enabled, but that's useless since I'm not using cookies. She tried the website in Safari, Mozilla, which have this double login issue, but MSIE does not. I was able to duplicate the problem on my computer using the latest version of Chrome (this doesn't happen in MSIE for me either). I can log in as a regular member, only logged in members can see the calendar from the menu. But once I click on the calendar, it goes back to the login screen. A 2nd login allows me to click on Calendar again, and it works fine. It's not an operater error such as != or whatever, because even this causes it to trigger a 2nd login: <?php if (!isset($_SESSION['Active'])) header('Location:login.php'); ?> I have an include file that creates the top of the website, then a menu that detects if you are "Active" or not after reading the database. This code is included on every single webpage. <?php if ($_SESSION['Active']<>"yes") { ?> <li><a href="login.php"><span>Login</span></a></li> <?php } else { ?> <li><a href="download_search.php" title="Downloads" rel="dropmenu1_c"><span>Downloads</span></a></li> <li><a href="calendar.php" title="Calendar"><span>Calendar</span></a></li> <li><a href="#" title="My Account" rel="dropmenu2_c"><span>My Account</span></a></li> . . . } So as you can see, the code ONLY shows the Calendar menu option if and only if you are logged in. When I log in, I can see and click on the Calendar href link. But apparently, when I click on the calendar option the first line of code in calendar.php causes me to re-login: <?php if (!isset($_SESSION['Active'])) header('Location:login.php'); ?> Here is the first several lines of code for my login.php: <?php session_start(); ?> <?php include("components/dbconnection.php"); /* Just check to see if the email field on the form is set */ if (isset($_POST["User_Email"])){ $UserEmail = $_POST["User_Email"]; $Password = $_POST["User_Password"]; $result = mysql_query("SELECT * FROM Members WHERE Email='$UserEmail' AND Pword='$Password'"); while($row = @mysql_fetch_array($result)) { if ($row['Active']=="yes" || $row['Active']=="guest") { /* Set the User_ID for later use to check and see if they are in leadership */ $UserID=$row['MemberID']; /* Set cookies to identify the user without accessing the database again */ $_SESSION['MemberID'] = $row['MemberID']; $_SESSION['Active'] = "yes"; $_SESSION['FirstName'] = $row['FirstName']; $_SESSION['LastName'] = $row['LastName']; . . . } Else { $Error="<span class='error'>Your login is correct, however, your account is currently not activated. Please contact an administrator.</span>"; } I sure hope someone can help me figure this out. I have no clue where to begin!
-
I have a strange issue that I cannot duplicate, so I'm wondering if someone here will see what's going on. When I login to the website, I have no issues. My wife has no issues. But two people across the country are having issues. So far, they are the only ones that I know of. The code checks the database to see if they are an active account and sets a session. It also checks to see if they are admin and sets a session id for that as well. Assuming they are both set correctly this is how I set the Sessions: $_SESSION['Active'] = "yes"; $_SESSION['Admin'] = $row['Admin']; // Assume that they are an admin and this is correct My menu is setup so that it expands if a person is set in the db as an admin. So the code obviously sees her as an admin when she logs in because she sees the admin options. I have this code at the top of the admin pages for security purposes: <?php if ($_SESSION['Admin']!=="yes"){header('Location:../login.php'); } ?> The result is that she logs in once, sees the admin options, and clicks one of them. It then redirects her back to the main login page. Then she logs in a 2nd time, sees the admin menus, and clicks one of them and everything works fine. Could it be something that I have done above, or something more browser specific?
-
I assume something is wrong with the path since it simply cannot find the file.
-
I have a directory that's full of .mp3, .pdf, .docx and other files. I use this file to fix the type in the header so the correct download options come up. Works great for all my files, including the .docx Let me know if this helped. <?php $File_Name=$_GET['file']; $File_Type = substr($File_Name, -4); switch ($File_Type) { Case ".mp3": $ContentType = "audio/mpeg3"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case ".avi": $ContentType = "video/avi"; $File_Path="Videos/"; $File_Location=$File_Path.$File_Name; break; Case (".doc" OR "docx"): $ContentType = "application/msword"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case ".gif": $ContentType = "image/gif"; $File_Path="Pictures/"; $File_Location=$File_Path.$File_Name; break; Case (".jpg" OR "jpeg"): $ContentType = "image/jpeg"; $File_Path="Pictures/"; $File_Location=$File_Path.$File_Name; break; Case ".wav": $ContentType = "audio/wav"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case ".m4a": $ContentType = "audio/m4a"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case (".mpg" OR "mpeg"): $ContentType = "video/mpeg"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case ".rtf": $ContentType = "application/rtf"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case ".pdf": $ContentType = "application/pdf"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; Case ".txt": $ContentType = "application/txt"; $File_Path="Music_Library/"; $File_Location=$File_Path.$File_Name; break; } @ob_end_clean(); // The following code makes the download non cacheable header("Cache-control: private"); header('Pragma: private'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header('Content-disposition: attachment; filename='.$File_Name); header('Content-type:'.$ContentType); readfile($File_Location); exit; ?>
-
I can't remove cookies in PHP for some reason.
TapeGun007 replied to TapeGun007's topic in PHP Coding Help
Ok, then I edited all the things I don't want people to see out, but this is really the main code for my login.php page. <?php /* Delete all associated cookies */ If ($_GET["logout"]=="yes") { setcookie("Active","",mktime(12,0,0,1, 1, 1990),"". ".sanjosechoir.com"); setcookie("MemberID","",mktime(12,0,0,1, 1, 1990), "", ".sanjosechoir.com"); setcookie("FirstName","",time()-186400, "", ".sanjosechoir.com"); setcookie("LastName","",time()-186400, "", ".sanjosechoir.com"); header('Location:login.php'); exit; } ?> <?php include("components/dbconnection.php"); /* Just check to see if the email field on the form is set */ if (isset($_POST["User_Email"])){ $UserEmail = $_POST["User_Email"]; $Password = $_POST["User_Password"]; $result = mysql_query("SELECT * FROM Members WHERE Email='$UserEmail' AND Pword='$Password'"); while($row = @mysql_fetch_array($result)) { if ($row['Active']=="yes") { /* Set the User_ID for later use to check and see if they are in leadership */ $UserID=$row['MemberID']; /* Set cookies to identify the user without accessing the database again */ setcookie("MemberID",$row['MemberID'],time()+3600*24); setcookie("Active",$row['Active'],time()+3600*24); setcookie("FirstName",$row['FirstName'],time()+3600*24); setcookie("LastName",$row['LastName'],time()+3600*24); $Active = "true"; } Else { $Error="<span class='error'>Your login is correct, however, your account is currently not activated. Please contact an administrator.</span>"; } } if ($Active=="true"){ $date = date("m/d/Y"); $MemberID = $_COOKIE['MemberID']; $result = mysql_query("UPDATE Members SET Last_Login='$date' WHERE MemberID='$MemberID'"); mysql_query($result); header('Location:index.php');; exit; } // $Error="<span class='error'>Invalid Username and/or Password</span>"; mysql_close($con); } ?> <?php include("components/header.php"); ?> <span class="ContentBold">Login:</span> <p> <form action="login.php" method="post"> <table border="2" bordercolor="#333333"><tr><td> <table cellpadding="2" cellspacing="0"> <tr> <td><b>Email:</b></td><td><input name="User_Email" value="<?php if (isset($_COOKIE['UserEmail'])) echo $_COOKIE['UserEmail'] ?>" class="input" /></td> </tr> <tr> <td><b>Password:</b></td><td><input name="User_Password" type="password" value="<?php if (isset($_COOKIE['UserPass'])) echo $_COOKIE['UserPass'] ?>" class="input" /></td> </tr> <tr><td colspan="2" align="center"><input src="images/btn_Submit.gif" type="image" align="middle" /> </td></tr> </table> </td></tr></table> </form> <?php if (isset($Error)) echo '<br>'.$Error."<p>"; ?><p> <p><p> Cookies that are still set:<p> <?php echo $_COOKIE['Active']."<br>"; echo $_COOKIE['MemberID']."<br>"; echo $_COOKIE['FirstName']."<br>"; echo $_COOKIE['LastName']."<br>"; ?> <?php include("components/footer.php"); ?> -
Ok, I'm just about at my wits end here. I cannot seem to remove cookies... period. I've tried everything, including Javascript in an attempt to get this to work. When programming in ASP, it was so simple and worked everytime, I would just code: Response.Cookies("FirstName").Expires = Date () -1 And it was done, no worries, no issues, no hassles. That cookie would be done with. In php however, I cannot get anything to work. Even closing the browser and reopening it does NOT get rid of the cookie. I've tried this in MSIE 8, Firefox, AND Chrome. I get the same result in each browser. I've even deleted all cookies on my system. As a matter of fact, I deleted everything that IE would allow me to delete to test. I've experimented with several things this code is in the login page.: If ($_GET["logout"]=="yes") { setcookie("Active","",mktime(12,0,0,1, 1, 1990),"". ""); setcookie("MemberID","",mktime(12,0,0,1, 1, 1990), "", ""); setcookie("FirstName","",time()-186400, "", ""); setcookie("LastName","",time()-186400, "", ""); header('Location:login.php'); exit; } At the bottom of the login.php page, I have this: echo $_COOKIE['Active']."<br>"; echo $_COOKIE['MemberID']."<br>"; echo $_COOKIE['FirstName']."<br>"; echo $_COOKIE['LastName']."<br>"; Ok, so assume that I have completely wiped my computer of all cookies and internet junk. I login to the page, the cookies are obviously setting correctly, so that's not an issue. $_COOKIE['Active'] always is set to "yes", and every other cookie is wiped out the FIRST time I log in and log off. If I log in and log out a 2nd time, all the cookies are intact and none of them are deleted. Can someone please explain what in the world I am doing wrong here? I'm extremely frustrated and coming here as a very last resort after exhausting myself on this subject! If you need something else from my code, let me know... I'll be glad to provide it.
-
I couldn't agree more, if it was my problem, I'd be working on the SQL side of things.
-
I only did Classic ASP, not ASP.net. ASP is very similiar to php (at least to me) except that ASP has MUCH less functionality and I presume some day that it will disappear. ASP.Net is actually more different from Classic ASP than php is. So the change wasn't that difficult. Especially considering that ASP.net servers cost a lot more $$ to get when I can get a great php server for like $5 a month!
-
Have you tried posted in the MySQL help section of this website? Perhaps creating a query that sorts and pulling the data from that would be easier than trying to pull unsorted data and using php to sort it. OR Maybe you can store the users into an array with a key, then store the money into an array with the same keys. Then sort the money array and match the keys in the user array? I don't know if this is accurate, only one of these guru guys can answer that. Php doesn't exactly do multidimensional array sort as I found out the hard way.
-
How I've learned both ASP, and PHP was simple. Find something you want to code that is fairly simple, like... creating a form, and writing that information to MySQL. You then google something like "Php forms" and read about it. Then google "php writing to mysql". Most of which I would copy someone else's code until I found a code that actually worked. I looked up all the commands they use so I can understand what they are doing. Eventually, I did it enough times that I knew what to code when and where. Granted, I'm still learning PHP, but I can code just enough to make a decent website. Now, when I have a problem that I just can't figure out, I turn to the guru's on this website and they have almost ALWAYS come through for me. It's truly amazing how helpful people are here.
-
Why would a hidden form tag work on a redirect? I don't understand that. I can see using a header redirect and passing along information like: header("Location:index.php?ID=<value>"); But without someone clicking on a submit button, how would this post?
-
Normally I would, but if the file doesn't exist, there would be no link, therefore, checking to see if it existed was pointless.
-
Yep, you're right. I removed the URL portion and linked directly to the local file and it works now! Thank you, I just could figure the thing out on my own.
-
I renamed the abbreviated file to .txt and opened it with notepad. Here is what it contains, I replace the domain name with <URL> <br /> <b>Warning</b>: readfile(<URL>/Music_Library/02 Create In Me.mp3) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in <b>/home2/sanjose3/public_html/download_file.php</b> on line <b>52</b><br /> File Name= 02 Create In Me.mp3<br>Content Type= audio/mpeg3<br>File Location= <URL>/Music_Library/02 Create In Me.mp3<br>File Type= .mp3<br> BTW, yes the files are local files as well. So... after reading your comment like 6 times, the readfile should be like readfile(/Music_Library/<filename>) instead of with a URL, correct?
-
I have a webpage that basically just dumps a directory full of files that contain .mp3, .pdf, and .doc files primarily. Before each filename are two options - Download or Open. (see example1.gif) I recently transitioned from a php 4.2 server to a 5.x server. Clicking on the "Open" link simply streams the files if it's a .mp3 and plays it. This works on both php 4.2 and 5.x servers. However, clicking on the Download link does something different. In php 4.2, when clicking the [ Download ] link, a menu pops up just in you see in example1.gif. I can select Open or Download. If I select Open, the file, again, simply streams and plays music if it's a .mp3 file. It works great. In php 5.x, when I click [ Download ] and then select Open, the file fails to play and gives an error as seen in example2.gif. If I click on the [ Download ] link and select Download from the menu, it saves a file, but it's a smaller filesize than a mp3 and will not open or play. Here is the code for the page that displays the files and the [ Download ] linking: <td nowrap bgcolor="<? echo $bgcolor ?>"><a href="download_file.php?file=<? echo substr($Value,0,$str_pos) ?>&path=<? echo $FilePath ?>">[ Download ]</a></td> So, $Value is equal to something like this "02 Create In Me.mp3|3.4 MB's", I split the string to show only the filename "02 Create In Me.mp3". If you notice, the link goes to download_file.php and passes the file name and path for the file (sub folder). Here is the code for download_file.php which tries to set the header based upon the file type so a user can download it: <?php $File_Path=$_GET['path']; $File_Name=$_GET['file']; $File_Location=$File_Path.$File_Name; $File_Type = substr($File_Name, -4); switch ($File_Type) { Case ".mp3": $ContentType = "audio/mpeg3"; break; Case ".avi": $ContentType = "video/avi"; break; Case (".doc" OR "docx"): $ContentType = "application/msword"; break; Case ".gif": $ContentType = "image/gif"; break; Case (".jpg" OR "jpeg"): $ContentType = "image/jpeg"; break; Case ".wav": $ContentType = "audio/wav"; break; Case ".m4a": $ContentType = "audio/m4a"; break; Case (".mpg" OR "mpeg"): $ContentType = "video/mpeg"; break; Case ".rtf": $ContentType = "application/rtf"; break; Case ".pdf": $ContentType = "application/pdf"; break; Case ".txt": $ContentType = "application/txt"; break; } @ob_end_clean(); // The following code makes the download non cacheable header("Cache-control: private"); header('Pragma: private'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header('Content-disposition: attachment; filename='.$File_Name); header('Content-type:'.$ContentType); readfile($File_Location); // You never see the text below print out unless I remark the 3 lines above this one to check for errors. echo "File Name= ".$File_Name."<br>"; echo "Content Type= ".$ContentType."<br>"; echo "File Location= ".$File_Location."<br>"; echo "File Type= ".$File_Type."<br>"; ?> My question is, how do I make this php 5.x compliant, since it works just fine in php 4.2? [attachment deleted by admin]
-
I did this a little different than above. All you need to check is if the db Date is equal to the date being output. So... <?php echo '<select name="dob-year">'; for ($i = 0; $i < 100; $i++) { $date_str = date('Y', strtotime("- $i years")); If ($dob_year==$date_str{ $selected="selected" } Else{ $selected=""; } echo "<option value=\"$date_str\" $selected>$date_str</option>";}echo "</select>"; ?> Hope that helps.
-
Well... I discovered that using: header('Location:login.php'); Works and using echo '<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">'; does not. For whatever reason, the META will not clear out the info and reset the cookies, but the header will. Which I'm assuming this goes back to what you were saying earlier about how cookies actually operate.
-
Thank you Alex for the reply. Why does this happen only in MSIE and not Firefox or Chrome then? And how can I fix this in IE specifically?
-
Ok, so I used to have my website located on an IP address while it was in development. Then I transferred the domain over to the new host. This used to clear all the cookies no problem, now it does not. If (isset($_GET["logout"])) { setcookie('Active','',time()-3600); setcookie("MemberID","",time()-3600); setcookie("FirstName","",time()-3600); setcookie("LastName","",time()-3600); setcookie("Admin","",time()-3600); setcookie("SuperAdmin","",time()-3600); setcookie("Admin_Rights","",time()-3600); // echo '<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">'; echo $_COOKIE['Active']."<br>"; echo $_COOKIE['MemberID']."<br>"; echo $_COOKIE['FirstName']."<br>"; echo $_COOKIE['LastName']."<br>"; echo $_COOKIE['Admin']."<br>"; echo $_COOKIE['SuperAdmin']."<br>"; echo $_COOKIE['Admin_Rights']."<br>"; exit; } The result is that these echo statement return values of the cookies under the domain name. However, if I go back and load this website through the IP address, they work just fine. I have tried to clear out the MSIE 8 cache and such, and restarting it, but it still continues to fail, but only if I load the website via the domain. Why?
-
You may want to read this topic that I posted earlier first: http://www.phpfreaks.com/forums/index.php/topic,301476.0.html What I'm doing is, listing a bunch of groups: (See SelectGroups.gif image below) Page 1: Once the user selects the groups they want, and click Submit, it then redirects to another form (Page 2) to select which songs they want to assign to those groups: (See SelectFiles.gif image below) Page 3: Write the information to a database. My question is, how do I pass the Groups that were selected on Page 1 to Page 2 (which I already did), and then pass them along to Page 3? [attachment deleted by admin]
-
Ah yes, that works perfectly. I was getting closer and closer to the answer. I knew there was a foreach command, just wasn't sure how. Plus, I didn't know you could simply pass the array like that. That's great! Thank you.
-
I have a database that contains several "Groups" that people belong to. My web page reads the database and spits out the groups onto the page. The form allows you to select which groups you want and passes this information onto the next page. (see picture) The form you see in the picture simply uses the input tag Checkbox. The checkbox is named in sequential order, so... Group1 = Choir Group2 = Chorale Group3 = Directors ..etc In classic ASP, the next page would read how many groups were selected with this code: Dim a For a = 1 to Request.Form("GroupName").Count Response.Write(Request.Form("GroupName")(a) & " was selected<BR>") Next How can I do this same thing in php? [attachment deleted by admin]