tcorbeil Posted April 5, 2007 Share Posted April 5, 2007 Is it possible to send an array variable like this? $flag['1']= "test"; $flag['2']= "me"; @header("Location: ".$_SERVER['HTTP_REFERER']?flag = $flag); would this work? Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/ Share on other sites More sharing options...
papaface Posted April 5, 2007 Share Posted April 5, 2007 I don't think so, but this would: $flag = array("test","me"); header("Location: ".$_SERVER['HTTP_REFERER']?flag=flag['1']); Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222135 Share on other sites More sharing options...
tcorbeil Posted April 5, 2007 Author Share Posted April 5, 2007 Here is the exact code of the script: <? // GET ALL FORM VARIABLES $UserName = $_POST['UserName']; $UserPassword = $_POST['UserPassword']; $VerifyPass = $_POST['VerifyPass']; $Email = $_POST['Email']; //function declaration //------------------------------------------------------------------------------------------------------------------ // FUNCTION CHMOD if (!function_exists('ftp_chmod')) { function ftp_chmod($ftp_stream, $mode, $filename) { return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename)); } } //------------------------------------------------------------------------------------------------------------------ // FUNCTION LOGIN INFO function loginmySQL() { include("/home/tcorbeil/public_html/Global/config.php"); mysql_connect(localhost, $config['dbUser'], $config['dbPassword']) or DIE(print_r($config, true)); @mysql_select_db(tcorbeil_SingleRegister); $config = null; // erase all database connection from memory. } //------------------------------------------------------------------------------------------------------------------ // CHECK USERNAME FOR CONTENT AND FOR DUPLICATES function ValUsername(){ !loginmySQL(); $query="SELECT * FROM `Personal_Register` WHERE UserName = '$UserName'"; $result=mysql_query($query) or die("Query failed: $query\nError: " . mysql_error()); $num_rows = mysql_num_rows($result); mysql_close(); if ($num_rows == 1) { $flag['UserTaken']= "The user name you entered has already been taken, please choose another user name."; } } //------------------------------------------------------------------------------------------------------------------ // CHECK FOR BLANK PASSWORDS AND RE-ENTRY VERIFICATION MATCH function ValPassword(){ if ($UserPassword != $VerifyPass) { $flag['PassMatch'] = "Your password entries do not match; Please re-enter your password."; } } //------------------------------------------------------------------------------------------------------------------ // VALIDATE EMAIL function ValEmail(){ if(preg_match("/^[a-zA-Z_]+(\w+)*((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/i",$Email)){ return true;} else { $flag['InvalidEmail'] = "Your email address is not valid, please re-enter your email address."; return false;} } //------------------------------------------------------------------------------------------------------------------ // LET'S MAKE SURE ALL FIELDS ARE FILLED OUT... function ValFormFilled(){ if ($UserName = ""){ $flag['UserNotFilled'] = "The user name field cannot be left blank, please enter a user name."; } If ($UserPassword == "") { $flag['PassNotFilled'] = "The password field cannot be left blank, please enter a password."; } If ($Email == "") { $flag['EmailNotFilled']= "The password field cannot be left blank, please enter a password."; } } !ValFormFilled(); if ($flag['UserNotFilled'] != ""){ !ValUsername(); } if ($flag['PassNotFilled'] != ""){ !ValPassword(); } if ($flag['EmailNotFilled'] != ""){ !ValEmail(); } @header("Location: ".$_SERVER['HTTP_REFERER']);.... basically I need to send the flag array back.. would the solution presented still be possible?? //$query="SELECT * FROM UserName WHERE UserName = '$UserName'"; //$result=mysql_query($query); //$row = mysql_fetch_array($result); // got the data now //$filename = $row['refdatabase']; ?> Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222138 Share on other sites More sharing options...
taith Posted April 5, 2007 Share Posted April 5, 2007 arrays cant be sent via $_GET... however if you $flag['1']= "test"; $flag['2']= "me"; foreach($flag as $k=>$v) $get.=$k.'='.$v; @header("Location: ".$_SERVER['HTTP_REFERER']?flag=$get); do that, the foreach changes that into a nice $_GET able string :-) Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222147 Share on other sites More sharing options...
tcorbeil Posted April 5, 2007 Author Share Posted April 5, 2007 Thanks for the tip Taith.. How would I get the info at the other end? something like $flag = $_GET['flag']; ECHO $flag['1']; ECHO $flag['2']; output on screen testme is this the way? Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222153 Share on other sites More sharing options...
tcorbeil Posted April 5, 2007 Author Share Posted April 5, 2007 Also, I get the error: Parse error: syntax error, unexpected '=' in /home/tcorbeil/public_html/Global/SingleValidate.php on line 91 line 91 being this line: @header("Location: ".$_SERVER['HTTP_REFERER']?flag=$get); Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222158 Share on other sites More sharing options...
taith Posted April 5, 2007 Share Posted April 5, 2007 sure... you can either declare the $file's seperatly... or automatically foreach($_SERVER['QUERY_STRING'] as $k=$v) $file[$k]=$v; if you have other stuff running through the $_GET, you prolly want to declare seperatly, or filter the variables, so you dont get any mixups :-) Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222161 Share on other sites More sharing options...
taith Posted April 5, 2007 Share Posted April 5, 2007 right... sorry $flag['1']= "test"; $flag['2']= "me"; foreach($flag as $k=>$v) $get.=$k.'='.$v; @header("Location: ".$_SERVER['HTTP_REFERER']?$get); Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222162 Share on other sites More sharing options...
tcorbeil Posted April 5, 2007 Author Share Posted April 5, 2007 Hey Taith. Thanks, that fixed that problem.. now i get the error: Parse error: syntax error, unexpected '=', expecting ')' in /home/tcorbeil/public_html/Dreamweaver/SingleRegister.php on line 62 line 62 being: foreach($_SERVER['QUERY_STRING'] as $k=$v) $file[$k]=$v; Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222168 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 You can use the serialize() function to convert an array to a string that can be put on the URL and then use the unserialize() to recreate the array. In your first script: <?php $flag = array('','test','me'); header('Location: ' . $_SERVER['HTTP_REFERER'] . '?flag=' . serialize($flag)); ?> In the second script: <?php $flag = unserialize(stripslashes($_GET['flag'])); echo '<pre>' . print_r($flag,true) . '</pre>'; // debugging line to check the results ?> Ken Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222169 Share on other sites More sharing options...
tcorbeil Posted April 5, 2007 Author Share Posted April 5, 2007 Hi Kenrbnsn. Thanks I'm a step closer.. But can I do something like: $messages = array('','test',$flag['PassNotFilled'],$flag['EmailNotFilled'],$flag['UserTaken'],$flag['PassMatch'],$flag['InvalidEmail']); If i do this, it seems the values from the variables do not pass but the hard text 'test' works... any ideas? Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222180 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Are the entries in the $flag array defined when you define the array? If not, just create a blank array and add them in when they are defined: <?php $messages = array(); $messages[1] = 'test'; // // // other code // // $messages[] = $flag['PassNotFilled']; $messages[] = $flag['EmailNotFilled']; // // etc... // ?> Ken Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222212 Share on other sites More sharing options...
tcorbeil Posted April 5, 2007 Author Share Posted April 5, 2007 Thanks.. anyway to get rid of ...SingleRegister.php?messages=a:1:{i:0;s:4:"tftf";} in the address bar after the transfer has been complete?? the problem is, if there are any errors, it goes back to the form, posts the errors and awaits a resubmit.. so when the user re-submits, where I would have simply SingleRegister.php, I now get SingleRegister.php?messages=a:1:{i:0;s:4:"tftf";} which is a problem... Thanks. Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222242 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 Pass the array via a session variable instead of putting it on the URL. In both scripts, put <?php session_start(); ?> at the beginning of the code. In the first script just before the "header" function put <?php $_SESSION['messages'] = $messages; ? In the second script, after the "session_start()" line put <?php $messages = $_SESSION['messages']; ?> Note: you shouldn't use the serialize function with this method. Ken Link to comment https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.