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
https://forums.phpfreaks.com/topic/29994-resolved-undefined-variable-ses/
Share on other sites

ooops didn't read all your post.

if all that is supposed to be one function you have terminated the curl_mail function after 6 lines of code.

If not that then you must trace back each assignment of each var that makes up $ses.
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
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"
In the last code you posted, you had called curl_mail() like this:
[quote]
curl_mail($_POST['username'],"Registration",$msg,"From: Private msgs Admin <[email protected]>");

[/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.

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.