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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222138
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222161
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222168
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222169
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222180
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222212
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222242
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
https://forums.phpfreaks.com/topic/45727-is-this-possible/#findComment-222250
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.