Jump to content

Is this possible?


tcorbeil

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.