Jump to content

[ resolved ] Undefined variable 'ses'


fert

Recommended Posts

i have this code:
[code]
function curl_mail($to,$subject,$msg,$headers)
{
$values=array("to"=>$to,"subject"=>$subject,"msg"=>$msg,"headers"=>$headers);
$cur=curl_init("http://www.mysite.net/mail_to.php");

curl_setopt($cur,CURLOPT_POST,true);
curl_setopt($cur,CURLOPT_POSTFIELDS,$values);

curl_exec($cur);
curl_close($cur);
}
$letters=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");

$num=rand(3,20);
for($count=0;$count<$num;$count++)
{
$sesid[$count]=$letters[rand(0,35)];
$ses.=$sesid[$count];
}

$result=@mysql_query("SELECT * FROM `users` WHERE `sesid`='$ses'",$cn) or die(mysql_error());
while(mysql_num_rows($result)!=0)
{
$num=rand(3,20);
for($count=0;$count<$num;$count++)
{
$sesid[$count]=$letters[rand(0,35)];
$ses.=$sesid[$count];
}

$result=@mysql_query("SELECT * FROM `users` WHERE `sesid`='$ses'",$cn) or die(mysql_error());
}

$pword=md5($_POST['password']);
$uname=mysql_real_escape_string($_POST['username']);
$e_mail=mysql_real_escape_string($_POST['email']);

@mysql_query("INSERT INTO `users` (username,password,email,sesid,active) VALUES('$uname','$pword','$e_mail','$ses','0')",$cn) or die(mysql_error());
curl_mail($_POST['username'],"Registration","Thank you for registering when logging for the first time use: {$ses} as your password","From: Person");
[/code]
when i run it i get a server error from the server that the curl_mail() function uses. any ideas why?
Link to comment
Share on other sites

with this code:
[code]
$ses=NULL;
$letters=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");

$num=rand(3,20);
for($count=0;$count<$num;$count++)
{
$sesid[$count]=$letters[rand(0,35)];
$ses.=$sesid[$count];
}
echo $ses;

$result=@mysql_query("SELECT * FROM `users` WHERE `sesid`='$ses'",$cn) or die(mysql_error());
while(mysql_num_rows($result)!=0)
{
$num=rand(3,20);
for($count=0;$count<$num;$count++)
{
$sesid[$count]=$letters[rand(0,35)];
$ses.=$sesid[$count];
}

$result=@mysql_query("SELECT * FROM `users` WHERE `sesid`='$ses'",$cn) or die(mysql_error());
}

$pword=md5($_POST['password']);
$uname=mysql_real_escape_string($_POST['username']);
$e_mail=mysql_real_escape_string($_POST['email']);

$msg="Thank you for registering when logging for the first time use: {$ses} as your password";
echo $msg;

@mysql_query("INSERT INTO `users` (username,password,email,sesid,active) VALUES('$uname','$pword','$e_mail','$ses','0')",$cn) or die(mysql_error());
//curl_mail($_POST['username'],"Registration",$msg,"From: Person");
[/code]
i get: 2jfn5qzljgsly3apogThank you for registering when logging for the first time use: 2jfn5qzljgsly3apog as your password
Link to comment
Share on other sites

The code that i posted is part of a script for users to register on my website I'm user the curl_mail() function because my server doesn't have a mail server and the server that the curl_mail() function accesses has one. If i take out the {$ses} out of the variables passed to the curl_mail() function the function works, otherwise i get a server error from the server that the curl_mail function uses. And when i log in my apache error log it says something along the lines of "PHP error: Undefined variable 'ses' on line 40 in htdocs/msgs/register.php. Refer htdocs/msgs/register.php"
Link to comment
Share on other sites

In the last code you posted, you had called curl_mail() like this:
[quote]
curl_mail($_POST['username'],"Registration",$msg,"From: Private msgs Admin <robert@usnet1.net>");

[/quote]

Did that work?  It should work better than what you had before because you've now defined a variable, $msg, that would contain the value of $ses.  It looks like the output echoed is what you are looking for.

I suspect the reason it didn't work the way you originally called curl_mail():
[quote]
curl_mail($_POST['username'],"Registration","Thank you for registering when logging for the first time use: {$ses} as your password","From: Person");

[/quote]
is because you literally passed "...use: {$ses} as..." and not the value of $ses.  Then, when the function tried to process the comment, it tried to parse $ses and that's where you got the error.
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.