variable problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

variable problem

Post by suhailkaleem »

<?

$n1 = $_GET['n1'];
if ($n1 == "0" ){
$n1= "" ;
}



//This does not work

$filename = "un".$n1.".txt";
$fd = fopen ($filename, "rb");
$username = fread ($fd, filesize ($filename));
echo $username;
fclose ($fd);
//unlink ($filename);

//This works
$username="suhailkaleem" ;

//This does not work
$filename = "pass".$n1.".txt";
$fd = fopen ($filename, "rb");
$password = fread ($fd, filesize ($filename));
echo $password;
fclose ($fd);
//unlink ($filename);

//This works
$password ="excel" ;


//This does not work
$filename = "servername".$n1.".txt";
$fd = fopen ($filename, "rb");
$server = fread ($fd, filesize ($filename));
echo $server;
fclose ($fd);
//unlink ($filename);

//This works
$server ="127.0.0.1";




$port = "110/pop3";
$mailserver = "{" . "$server:$port" . "}INBOX";





$link = imap_open($mailserver, $username, $password);
$total = imap_num_msg($link);
echo $total ;
imap_close($link);



//The baove code does not work why ? but when i put constant value in varibales user name
//password and server it works but dynamuic values dont work , correct values are cooming from file but i always get an error
// Couldn't open stream {127.0.0.1 :110/pop3}INBOX in D:\p\test.php on line 48
//can any one tell me how can i use dynamic vlaues instead of condtant values
//anyhelp
//suhailkaleem

?>
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

Post by suhailkaleem »

Any help i am still stuck with this
Thanks
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Are you sure that $_GET['n1']; is returning a value?

try echoing it and see what it returns?!?

Check that you dont have any trailing whitespace on the end of any of the variables, you may need to chop() them!!!!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you can print all parameters passed via GET/POST with

Code: Select all

&lt;?php
echo '&lt;pre&gt;GET:'; print_r($_GET);
echo "\nPOST:"; print_r($_POST);
echo '&lt;/pre&gt;';
?&gt;
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

Post by suhailkaleem »

i did check the values they return the correct values but imap function dont accpet them ??? why is that ? it still give the same error
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

Post by suhailkaleem »

any help ?
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

When you say, "This doesn't work" what do you mean?

Firstly, if you copied and pasted your error:
{127.0.0.1 :110/pop3}INBOX
Notice the "space" between your server and port.


Secondly, what does not work with the following code? Are you not getting the file to open, or provide you with a value, or something else?
$filename = "un".$n1.".txt";
$fd = fopen ($filename, "rb");
$username = fread ($fd, filesize ($filename));
echo $username;
fclose ($fd);
Have you tried using a fake-dynamic filename:

Code: Select all

&lt;?php
$filename = "un3.txt";  // Check to make sure this file exists
$fd = fopen ($filename, "rb"); 
$username = fread ($fd, filesize ($filename));  // does the file only contain one word on one line?
echo $username;  // is anything be echoed here?
fclose ($fd); 
?&gt;
suhailkaleem
Forum Newbie
Posts: 12
Joined: Thu Nov 07, 2002 9:11 am
Contact:

Post by suhailkaleem »

Code: Select all

/*
hi !
 
 yes you were right there is space between server name but still i am unable to remove it 


$username ,$password,$server are comming from file and they have correct values
*/

$username1 = $username;
$password1 = $password;
$server1 = $server;
echo $server."test<BR>" ;
echo $password."test<BR>" ;
echo $username."test<BR>" ;

  /* 
This echo  
127.0.0.1 test
excel test
suhailkaleem test

    it echo with a space between variable value and the string test .there is space in text file at the end of these values ?


*/



$username = "suhailkaleem";
$password = "excel";
$server = "127.0.0.1";
echo $server."test" ;
// This echo 127.0.0.1test   no space 




/* 
why is that i see space between server and string when the values come from the text file  , although there is no space in text file  at the end of server name  but when i use in my script the space appears????? 
*/
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

have you tried chop() on the variables to get rid of the spaces on the end of them????
mikey
Forum Newbie
Posts: 1
Joined: Fri Nov 29, 2002 8:30 am

Post by mikey »

HI

Had a similar problem with variables. Make sure in the php.ini file
the the using of global variables is activated.

You'll find that option in the php.ini file some lines upper than the middle.
=> register_globals = on. Default ist off.

grz, mikey
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the variables are read from a file. register_globals has no effect on that ;)

fgets (which you might have used) also returns the line delimiter.
So if you have a file like

Code: Select all

uid1,pass1,server1
uid2,pass2,server2
...

Code: Select all

$content = file($filename);
foreach($content as $entry)
	list($username, $password, $server) = explode(',', $entry);
will make $server == "server1\n"; and chop() (as mentioned by Wayne) will take care of it. It's an alias for rtrim (http://www.php.net/manual/en/function.rtrim.php)
This function returns a string with whitespace stripped from the end of str. Without the second parameter, rtrim() will strip these characters:
...
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
...
abdul
Forum Newbie
Posts: 24
Joined: Thu Nov 14, 2002 7:35 am

Post by abdul »

What about this,

Code: Select all

$username1 = trim($username);
$password1 = trim($password);
$server1 = trim($server);
echo $server."test<BR>" ;
echo $password."test<BR>" ;
echo $username."test<BR>" ;
Cheers!

-Abdul
Post Reply