|
Hi sorry I am just a baby in PHP. I want to get the value of $_SESSION['username'] but it gives me this error : Notice: Undefined offset: 0. Please see my code below. Your help will be greatly appreciated. Thanks.
";
echo $_SESSION[0]; //I want an output "andrew" but it fails.
|
|
|
|
|
$_SESSION (see PHP: $_SESSION - Manual[^] ) is an associative array containing key value pairs (see PHP: Arrays - Manual[^]).
These are not accessed by an index but by their keys which might be integers or strings. Because you have not assigned a value with the key '0' you will get the error.
Just use the key instead:
echo $_SESSION['username'];
|
|
|
|
|
|
Hi all,
I got a problem
I used CentOS 7.1,
used command: yum -y install httpd to install apahce
used command: yum -y install php to install php
noting to change the configure file /etc/httpd/conf/httpd.conf
and then I have done this two things in /var/www/html/:
1. ln -s /home/ninja/workspace/storage .
2. create a test file test.php
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# ls
storage test.php
[root@localhost html]# ll
total 4
lrwxrwxrwx 1 root root 29 Dec 28 20:05 storage -> /home/ninja/workspace/storage
-rwxr-xr-x 1 root root 122 Dec 28 20:04 test.php
[root@localhost html]# cat test.php
<?php
echo "====================\n";
$data = file_get_contents("./storage/8010252");
echo "get data";
echo $data;
?>
the file 8010252 does really there, but php can not access.
the apache error log shows:
[Wed Dec 28 20:06:46.858835 2016] [:error] [pid 8605] [client 192.168.3.57:26918] PHP Warning: file_get_contents(./storage/8010252): failed to open stream: No such file or directory in /var/www/html/test.php on line 4
If I don't use Symbolink, it works, it seems like apache can not access the Symbolink folder.
Anyone can help, Thanks a lot.
Solution:
To solve this problem, I just run the command:
chmod -R +x /home/ninja
and then it works!
modified 28-Dec-16 21:15pm.
|
|
|
|
|
I got the following error trying to install a package error while loading shared libraries libio_misc.so
I am not familiar with Linux would anyone know what this means
|
|
|
|
|
The message tells you it had trouble loading a .so file (a shared object file, similar to a .dll in Windows). However with that little detail it is anyone's guess what the actual problem is.
|
|
|
|
|
I was trying to install IBM zpdt package or rather executing a command I am wondering just as in the case of Windows DLL if I google the name can I some how download it ?
|
|
|
|
|
Possibly, but you will need to first find out why it failed before.
|
|
|
|
|
Probably couldn't find the library. First, search your system to see if you have that library (look in /usr/lib, /usr/local/lib, or multiarch lib paths[^] if Suse supports them), if you don't find it do an online search to see what package that library is a part of and install that package.
If you find the library in your system already but you're still getting an error, it's also possible that whatever you're running is looking in the wrong location or under the wrong name. For example, if it's looking for libio_misc.so but your system has libio_misc.1.2.0.so (in which case, you just need a symbolic link). If the shared object file is in a non-standard location and you want to add search paths to the loader, you just have to define or add to the LD_LIBRARY_PATH environment variable.
|
|
|
|
|
Hi, I am basically a software developer looking for a laravel based admin template with all the Advanced functionalities which can save my tons of hours of production so that i can develop my projects at a quicker pace,can anyone please suggest me regarding this?
|
|
|
|
|
|
Hi all,
It's a Nginx and PHP web project, When I run a php script as shell, there shows Access Denide!
X-Powered-By: PHP/7.0.9
Content-type: text/html; charset=UTF-8
Access Denied!
The php file is like this:
#!/usr/bin/php-cgi
<?php
require_once("config.php");
require_once("util.php");
...
..
.
file_put_contents($argv[1], CJSON::encode($obj));
?>
I have try to change all the php file as 777, and try to run like this:
./list.php /home/cache.json
/usr/bin/php list.phph /home/cache.json
Still can not work.
and then I try to make a new php script test.php:
#! /usr/local/php7/bin/php-cgi
<?php
echo "php test";
?>
and then run it:
/usr/local/php7/bin/php-cgi test.php
it works:
[root@localhost ~]# /usr/local/php7/bin/php-cgi test.php
X-Powered-By: PHP/7.0.9
Content-type: text/html; charset=UTF-8
php test
I don't now why, anyone can help? Thanks for advance.
|
|
|
|
|
I think your path to the output file may be wrong. The directory /home is a system directory that contains the user home directories, one for each user. The command ls -l /home will show you what it is and what permissions it has.
Try just:
./list.php cache.json
// or
./list.php ~/cache.json
|
|
|
|
|
hello all,
i am having this issue with trying to connect my php app to sql server and i have edited the php.ini with the required driver needed to the php version 5.5. Below is the error i get anytime i try to connect to the database, i will appreciate if anybody will help with this.
Database connection refused.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) )
"
|
|
|
|
|
What part of those instructions are you having a problem with?
|
|
|
|
|
I did the connection from the php using these lines of code "
$serverName = "(THAIWO)";
$connectionInfo = array("Database"=>"examples");
$conn = sqlsrv_connect($serverName,$connectionInfo);
if ($conn){
echo ("Database connection Successful.<br />") ;
}else
{
echo ("Database connection refused.<br />") ;
die(print_r(sqlsrv_errors(), true));
}
"
i did download for
php_pdo_sqlsrv_55_ts.dll
php_pdo_sqlsrv_55_nts.dll
php_sqlsrv_55_ts.dll ,
php_sqlsrv_55_nts.dll
with all these done and checking for solution in the MSDN libary where i used the PDO syntax for connecting to sql server using the function sqlsrv_connect, am still at lost for where am doing things wrong. I want to know why i am refused and the reason for asking for the ODBC driver when i have downloaded and enabled it.
|
|
|
|
|
taiwokaffo wrote: i did download for That's the plugin for PHP, not the ODBC-driver. Follow the link in the instructions, download it and install it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks all it now working i used this to connect to the sql server 2012
$serverName = "OurIPAddress";
$connectionInfo = array( "Database"=>"Thenameofourdatabase", "UID"=>"OurID", "PWD"=>"Ourpassword");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
|
|
|
|
|
Hy everyone ..... I have to select php final year project..... suggest me some unique ideas ...... what sort of application i choose?
|
|
|
|
|
How should we? We have no idea at what level you are, what you have learned, how many time you have to finish and so on...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Choose something that you understand, and is within the limits of your skills and experience.
|
|
|
|
|
where to find your framework...link me
|
|
|
|
|
|
Hello. I have a list of numbered folders. In each folder there is a lot of .jpg files. I get a list of all including image files from this directories with two glob functions dynamically. I store a list of directory paths and filenames into two separates arrays called $DIR[] and $files[].
<?php
$pathDIR = "dirname/";
$DIR = Array(
);
foreach (glob($pathDIR . '/[0-30]*', GLOB_ONLYDIR) as $dirname) {
$DIR[] = $dirname;
}
for($a = 0; $a < count($DIR); $a++) {
echo $DIR[$a];
}
$pathFILE = Array();
$files = Array();
for($b = 1; $b <= count($DIR); $b++) {
$pathFILE[$b] = "dirname/" . $b . "/";
foreach(glob($pathFILE[$b] . '*.jpg') as $filename) {
$files[] = $filename;
}
}
for($c = 1; $c <= count($files); $c++) {
echo $files[$c-1];
}
?>
I have tried to combine two arrays in one multidimensional array with:
array_push ($DIR, $file);
to display array values I've tried with a pair of loops:
for($d = 0; $d <= count($DIR); $d++) {
for($e = 0; $e <= count($DIR[$d]); $e++) {
echo $DIR[$d][$e];
}
}
unfortunately array values are not properly show. Also, a notice indicate undefined offset .
Thanks a lot for your help.
|
|
|
|
|
My proposition is to modify the code in the following way:
<?php
$pathDIR = "dirname/";
$DIR = Array(
);
foreach (glob($pathDIR . '/[0-30]*', GLOB_ONLYDIR) as $dirname) {
$DIR[] = $dirname;
}
for($a = 0; $a < count($DIR); $a++) {
echo $DIR[$a];
}
$pathFILE = Array();
$files = Array();
for($b = 1; $b <= count($DIR); $b++) {
$pathFILE[$b] = "dirname/" . $b . "/";
$files[$b] = Array();
foreach(glob($pathFILE[$b] . '*.jpg') as $filename) {
$files[$b][] = $filename;
}
}
for($d = 1; $d <= count($files); $d++) {
for($e = 0; $e <= count($files[$d]); $e++) {
echo $files[$d][$e];
}
echo "\r\n\r\n";
}
?>
remember you can display files simlper way:
var_dump($files);
|
|
|
|