PHP + Flash Problems

Discuss actionscript in general, or relative to web development.

PHP + Flash Problems

Postby Gukkie » Wed Feb 17, 2010 11:10 am

Hi, i am currently making a flash header for my website, i have a login function in that header and it is connected to a php script, the problem is that i cannot get the values to pass into the flash header, my Logout function works fine without any problems but my Login doesnt, if i input the details and click login, the page does not refresh, i have to manually refresh the browser in order for it to work. Any ideas?

PHP SCRIPT:
  1. <?php
  2.  
  3. if ($_POST['email'] != "") {
  4.  
  5. include_once "connect_to_mysql.php";
  6.  
  7. $email = $_POST['email'];
  8. $pass = $_POST['pass'];
  9. $remember = $_POST['remember']; // Added for the remember me feature
  10.  
  11. $email = strip_tags($email);
  12. $pass = strip_tags($pass);
  13. $email = mysql_real_escape_string($email);
  14. $pass = mysql_real_escape_string($pass);
  15. $email = eregi_replace("`", "", $email);
  16. $pass = eregi_replace("`", "", $pass);
  17.  
  18. $pass = md5($pass);
  19.  
  20. //make query
  21. $sql = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$pass' AND email_activated='1'");
  22. $login_check = mysql_num_rows($sql);
  23.  
  24. if($login_check > 0){
  25.  
  26.     while($row = mysql_fetch_array($sql)){
  27.  
  28.         $id = $row["id"];  
  29.         session_register('id');
  30.         $_SESSION['id'] = $id;
  31.        
  32.         $username = $row["username"];  
  33.         session_register('username');
  34.         $_SESSION['username'] = $username;
  35.        
  36.         $email = $row["email"];  
  37.         session_register('email');
  38.         $_SESSION['email'] = $email;
  39.          
  40.         mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id'");
  41.    
  42.         $my_msg = "all_good";
  43.         print "return_msg=$my_msg&id=$id&username=$username";
  44.          
  45.     } // close while
  46.    
  47.     // Remember Me Section Addition... if member has chosen to be remembered in the system
  48.     if($remember == "yes"){
  49.       setcookie("idCookie", $id, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
  50.       setcookie("usernameCookie", $username, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
  51.       setcookie("emailCookie", $email, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
  52.       setcookie("passCookie", $pass, time()+60*24*60*60, "/"); // 60 days; 24 hours; 60 mins; 60secs
  53.     }   
  54.    
  55. } else {
  56. $my_msg = "no_good";
  57.     print "return_msg=$my_msg";
  58.   exit();
  59. }
  60.  
  61.  
  62. }// close if post
  63. ?>


Actionscript 3.0
  1. stop();
  2.  
  3. //email_txt.tabIndex = 1;
  4. //password_txt.tabIndex = 2;
  5. //sumbit_btn.tabIndex = 3;
  6. ////////////
  7.  
  8. // Assign a variable name for our URLVariables object
  9. var variables:URLVariables = new URLVariables();
  10.  
  11. //  Build the varSend variable
  12. var varSend:URLRequest = new URLRequest("http://localhost/scripts/login.php");
  13. varSend.method = URLRequestMethod.POST;
  14. varSend.data = variables;
  15.  
  16. // Build the varLoader variable
  17. var varLoader:URLLoader = new URLLoader;
  18. varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  19. varLoader.addEventListener(Event.COMPLETE, completeHandler);
  20.  
  21. // Handler for PHP script completion and return
  22. function completeHandler(event:Event):void{
  23.    
  24.     status_txt.text = "";
  25.    
  26.     if (event.target.data.return_msg == 'no_good') {
  27.        
  28.             status_txt.text = "No match in our records, please try again";
  29.            
  30.     } else if (event.target.data.return_msg == 'all_good') {
  31.  
  32.             var reloadPage:URLRequest = new URLRequest("javascript&#058;NewWindow=window.location.reload(); NewWindow.focus(); void(0);");
  33.             navigateToURL(reloadPage,"_self");
  34.        
  35.     }
  36.        
  37. }
  38.  
  39. // Add an event listener for the submit button and what function to run
  40. submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
  41.  
  42. // Validate form fields and send the variables when submit button is clicked
  43. function ValidateAndSend(event:MouseEvent):void{
  44.    
  45.     // "Remember Me" addition code for the checkbox variable------------
  46.     var rememberChoice:String;
  47.     ////////////////// remember me variable setup/////////////
  48.     if (rememberCheckbox.currentFrame == 2) {
  49.         rememberChoice = "yes";
  50.     } else {
  51.         rememberChoice = "no";
  52.     }
  53.     // End "Remember Me" addition code for the checkbox variable-------
  54.    
  55.     status_txt.text ="";
  56.     //validate form fields
  57.     if(!email_txt.length) {
  58.  
  59.         status_txt.text = "Please enter your email address.";   
  60.      
  61.     } else if(!password_txt.length) {
  62.  
  63.         status_txt.text = "Please enter your password.";   
  64.  
  65.     } else {
  66.        
  67.         // Ready the variables for sending
  68.         variables.email = email_txt.text;
  69.         variables.pass = password_txt.text;
  70.         variables.remember = rememberChoice; // Added for Remember me checkbox
  71.  
  72.         // Send the data to the php file
  73.         varLoader.load(varSend);
  74.  
  75.         //status_txt.text = "Logging in...";
  76.  
  77.     } // close else after form validation
  78.  
  79. } // Close ValidateAndSend function //////////////////////////////////////////////////////////////
  80.  
Gukkie
 
Posts: 22
Joined: Sat Feb 13, 2010 6:05 am
Online: 0s
Karma: 0

Re: PHP + Flash Problems

Advertisment

Advertisment
 

Re: PHP + Flash Problems

Postby wide_load » Wed Feb 17, 2010 12:11 pm

This is not really related to the problem but you should be be using regular expression functions to do this ...
  1. $email = eregi_replace("`", "", $email);
  2. $pass = eregi_replace("`", "", $pass);


as you are. Ot useing a correct regular expression php has a function for this
  1. $email = str_replace("`", "", $email);
  2. $pass = str_replace("`", "", $pass);


is the correct was to do it

The eregi functions take a out 3 times as long as simple str_replace
Image
User avatar
wide_load
Top Contributor
 
Posts: 5617
Joined: Thu Aug 13, 2009 1:04 pm
Online: 13d 22h 13m 24s
Karma: 45

Re: PHP + Flash Problems

Postby Gukkie » Wed Feb 17, 2010 12:23 pm

Thanks for the tip wide_load, hmm how about the problem i am having with making my login function refresh the page and get the values from the php script?
Gukkie
 
Posts: 22
Joined: Sat Feb 13, 2010 6:05 am
Online: 0s
Karma: 0


Return to ActionScript

Who's online?

Users browsing this forum: No registered users and 1 guest