I'm getting the current date-time.but not getting the ip address....the output is ::1 ..why this is happening ?enter image description here
<?php
defined('BASEPATH') or exit('No Direct Script Access Allowed');
class Ip_address extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function index(){
// var_dump($_SERVER);
$this->load->helper('date');
echo $date = "Current Time Is: ". date('Y-m-d H:i:s');
echo "<br/>";
echo $this->input->ip_address();
}
}
The IP ip of ::1 is identical to 127.0.0.1. If you want see the address like 192.168.x.x then you may try with another computer for example you set computer A as local server then you open the system on computer B (must be on the same network), you will see the different address printed.
You may try and give feedback.
Your Apache is listening for IPv6 connections by default (::1 i.e. localhost). If you just want IPv4, try to disable IPv6 connections in your Apache configuration.
If you want to get a different IP address, then you'll need to connect to the server through a different network interface.
Related
I have a controller that should give permission to use a resource for one IP. If the IP is an invalid controller should give a customized error "Not correct IP".
But when executing the controller, I keep getting the customized error "Not correct IP".
When I send $request->ip() I get "::1"
I am using localhost
My controller
class OhDayHiepController extends Controller
{
const ALLOWED = [
"5.5.5.5",
];
public function whiteIP (Request $request)
{
abort_unless(in_array($request->ip(), self::ALLOWED), die("Not correct IP"));
return $request;
}
}
Why my mistake and why I get ::1. Maybe coz localhost and need custom
"::1" stands for "localhost" in IPv6. You seem to be using IPv4 (xxx.xxx.xxx.xxx).
I don't know what you're trying to achieve so I can't give you the solution for sure, but you can try already with "::1" instead of "5.5.5.5" in ALLOWED.
There must also be a way to configure your local server to use IPv4 only.
I have this error when i am trying to access a website from wamp, it is done in codeigniter.
Error:
localhost is currently unable to handle this request. HTTP ERROR 500
homeindex controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class HomeIndex extends CI_Controller {
public function __construct(){
parent:: __construct();
$this->load->helper('html');
$this->load->helper('form','url','file');
$this->load->library('session','upload');
}
public function index()
{
//$this->load->view('coming_soon');
$this->load->view('homeIndex');
}
}
route
$route['default_controller'] = 'HomeIndex';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I am able to access other website which are not done using any frameworks.
This website is done using codeigniter. I am not able to access the website.
Can anyone tell me what is the problem?
Multiple loads with one call are done using an array:
$this->load->helper(array('form','url','file'));
$this->load->library(array('session','upload'));
https://www.codeigniter.com/user_guide/libraries/loader.html#CI_Loader::helper
if that doesn't work turn on error reporting (switch to development mode in index.php) and see what the actual error is. 500 error can be many things...
I'm unable to get the IP address of the client which I need to determine his current location.
I've used request->ip(), $_SERVER['REMOTE_ADDR'] and I always get a 127.0.0.1 result which is not what I want.
What am I doing wrong?
Sometimes your clients use your application through a proxy, so you should not depend on $_SERVER['REMOTE_ADDR'].
Check out this link (with a little concern on securities):
How to get the client IP address in PHP?
request->ip() will give you client IP. You're getting 127.0.0.1 in because you're trying to access your local project from the same machine.
I found a way how to fix it. But beware that you have to change it before going production!!
Read this part: https://laravel.com/docs/5.7/requests#configuring-trusted-proxies
And now just add this:
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* #var array
*/
protected $proxies = '*';
Now request()->ip() gives you the correct ip
You can try this:
function get_ip() {
$keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
foreach ($keys as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
return $ip;
}
}
}
}
}
There is client IP address this code($_SERVER['REMOTE_ADDR']) applied online project then it will work successfully . it will try..
Not working SMTP_validateEmail on live site using php
https://code.google.com/p/php-smtp-email-validation/
<?php
/**
* Example 1
* Validate a single Email via SMTP
*/
// include SMTP Email Validation Class
require_once('smtp_validateEmail.class.php');
// the email to validate
$email = $_POST['name'];
// an optional sender
$sender = $_POST['name'];
// instantiate the class
$SMTP_Validator = new SMTP_validateEmail();
// turn on debugging if you want to view the SMTP transaction
//$SMTP_Validator->debug = true;
// do the validation
$results = $SMTP_Validator->validate(array($email), $sender);
// send email?
if ($results[$email]) {
echo 1;
} else {
echo 0;
}
enter code here
?>
i am having problem on live site but it works fine in localhost.it shows the print_r($results) in the localhost but shows array(0) result in live.i also find $this->sock value in the class smtp_validateEmail.class function validate(email) value empty in live. how to solve this issue any help will be very thankful.
That "Add your web server ip address to var $nameservers = array(‘192.168.0.1’); and if your web server has Port number then update it here var $port = (Port number); Hope you will get the output by making this changes." Only work if you are sending mail with that script but cant tell if that mail checked is good one or not... I have been testing the code, try all changes, but still cant check other mails outside my domain. I can only make it work on my local and webserver host. Still cant call other servers to check if other mails from outside my domain are valid. Working on it.
Complete downloads are here for others to test : https://code.google.com/p/php-smtp-email-validation/downloads/list
Add your web server ip address to var $nameservers = array(‘192.168.0.1’);
and if your web server has Port number then update it here var $port = (Port number);
Hope you will get the output by making this changes.
Hello all im working on a project but when i upload my project i got a error you can see here
http://rapcom.dk/profil/index/KoS
but i think im doing it work cause it works on my local PC :S, here is my controller
function index()
{
$this->load->model('profil_model');
$data['query'] = $this->profil_model->vis_profil($this->uri->segment(3));
//Henter lib profilwall så man kan vise wall beskeder i profilen
$this->load->library('profilewall');
$data['queryWall'] = $this->profilewall->wallShow();
$this->template->write_view('content', 'profil_view', $data);
$this->template->render();
}
And my library called profileWall.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Profilewall
{
private $CI;
public function __construct()
{
$this->CI =& get_instance();
}
public function wallShow()
{
$this->CI->load->model('profil_model');
return $this->CI->profil_model->wallGet($this->CI->uri->segment(3));
}
}
do you know what can be wrong? and im 100% sure it is uploaded du the server
This may have to do with how you are naming the actual file. Could you try naming the file profilewall.php rather than profileWall.php and see if that works.
For the most part you should be mindful of case issues, especially with CodeIgniter. Generally the rule of thumb is to use lowercase characters in filenames, models, etc.