Page 1 of 1
variable problem
Posted: Thu Nov 07, 2002 9:16 am
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
?>
Posted: Thu Nov 14, 2002 4:23 am
by suhailkaleem
Any help i am still stuck with this
Thanks
Posted: Thu Nov 14, 2002 5:36 am
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!!!!!
Posted: Thu Nov 14, 2002 6:54 am
by volka
you can print all parameters passed via GET/POST with
Code: Select all
<?php
echo '<pre>GET:'; print_r($_GET);
echo "\nPOST:"; print_r($_POST);
echo '</pre>';
?>
Posted: Thu Nov 14, 2002 1:18 pm
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
Posted: Sun Nov 17, 2002 4:08 am
by suhailkaleem
any help ?
Posted: Sun Nov 17, 2002 9:27 am
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
<?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);
?>
Posted: Mon Nov 18, 2002 3:00 am
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?????
*/
Posted: Thu Nov 21, 2002 4:47 am
by Wayne
have you tried chop() on the variables to get rid of the spaces on the end of them????
Posted: Fri Nov 29, 2002 8:30 am
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
Posted: Fri Nov 29, 2002 1:22 pm
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.
...
Posted: Fri Nov 29, 2002 3:41 pm
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