Changing logo based on incoming domain using php - php

I am trying to change the logo based on what domain the visitor is using to view the website. I found some code in another topic on this site, but i was unable to make it work, so i was wondering if anyone of you can see what i'm doing wrong.
This is my code:
<?php
function logoSwap(){
switch($_SERVER['HTTP_HOST']) {
case 'liceng.dk':
$logo = "http://www.liceng.dk/images/liceng-logo.png";
break;
case 'www.liceng.dk':
$logo = "http://www.liceng.dk/images/liceng-logo.png";
break;
case 'licenergy.co.uk':
$logo = "http://www.liceng.dk/images/licenergy-logo.jpg";
break;
case 'www.licenergy.co.uk':
$logo = "http://www.liceng.dk/images/licenergy-logo.jpg";
break;
case 'http://licenergy.co.uk/':
$logo = "http://www.liceng.dk/images/licenergy-logo.jpg";
break;
default:
$logo = "http://www.liceng.dk/images/liceng-logo.png";
break;
};
return $logo;
}
?>
<?php
if(!empty($image)) {
echo '<h1>LIC Engineering A/S</h1>';
}
else {
echo '<img src="'.logoSwap().'" alt="LICeng logo">';
}
?>
Shouldn't it work? You can check the site here: www.liceng.dk

Related

Redirect to image from PHP result error 500

Here is the HTML
<img src="http://example.com/images/img.php?image=1" />
This is the img.php file
<?php
switch ($_GET['image']) {
case "1":
$image = 'photo-1.jpg';
break;
case "2":
$image = 'photo-2.jpg';
break;
case "3":
$image = 'photo-3.jpg';
break;
default:
$image = 'photo-1.jpg';
}
header('Content-Type: image/jpg');
readfile('some/folder/'.$image);
?>
When I access http://example.com/images/img.php?image=1 directly, always success, never error 500.
But when I put it on src, it's generate error 500, sometimes.
Why? Is there anything wrong?
Thank you.
solved
just increase php memory_limit and everything is fine

Steam API get current user status

I'm trying to use the steam web API to show the current status of ONE steam user if he is (online,away,offline,looking to trade) etc and have setup a PHP switch as follows:
<?
$status = $steamprofile['personastate'];
switch($status) {
case 0:
echo "offline!";
break;
case 1:
echo "online!";
break;
case 2:
echo "Busy.";
break;
case 3:
echo "Away.";
break;
case 4:
echo "Snooze.";
break;
case 5:
echo "Looking to trade.";
break;
case 6:
echo "Looking to play.";
break;
default:
echo "Unknown status";
}
echo $status;
?>
It works great but only shows the user status when logged unto the site and not simply when the user is online/away/offline etc on the steam platform.
I'm wondering if anyone know how to fix so it displays the current user status on steam, not just if he/she is logged in on the website.

how to get image location from database using ID

I am working on my website using wordpress to view and change cover for user by clicking on photo and then redirect him for example to process.php?pid=12
I am using
switch($GetPicId)
{
So I can't add more pic I but now I have script to upload pic using database, and I wanna to get id and pic location from by using database
First this is the upload script
and this is switch code
$GetPicId = $_GET["pid"]; // Picture ID from Index page
$PicLocation ='';
/*
Users do not need to know original location of image.
I think it's better to get image location from database using ID.
for demo here i'am using PHP switch.
*/
switch($GetPicId)
{
case 1:
$PicLocation = 'cover_pics/cover1.jpg';
break;
case 2:
$PicLocation = 'cover_pics/cover2.jpg';
break;
case 3:
$PicLocation = 'cover_pics/cover3.jpg';
break;
case 4:
$PicLocation = 'cover_pics/cover4.jpg';
break;
case 5:
$PicLocation = 'cover_pics/cover5.jpg';
break;
case 6:
$PicLocation = 'cover_pics/cover6.jpg';
break;
case 7:
$PicLocation = 'cover_pics/cover7.jpg';
break;
case 8:
$PicLocation = 'cover_pics/cover8.jpg';
break;
case 9:
$PicLocation = 'cover_pics/cover9.jpg';
break;
case 10:
$PicLocation = 'cover_pics/cover10.jpg';
break;
case 11:
$PicLocation = 'cover_pics/cover11.jpg';
break;
default:
header('Location: ' . $homeurl);
break;
}
Just Try
$GetPicId = $_GET["pid"]; // Picture ID from Index page
$sql=mysql_query("SELECT piclocation FROM tableName WHERE pid=$GetPicId") or die(mysql_error());
$res=mysql_fetch_array($sql);
$PicLocation = $res['piclocation '];
Use this to get attachment url ..Your cover images are uploaded in media right??
Then try this
<?php wp_get_attachment_url( $id ); ?>
it will become something like this
$GetPicId = $_GET["pid"]; // Picture ID from Index page
$PicLocation =wp_get_attachment_url( $GetPicId);

Uploaded and resized photo in Codeigniter is not available in view until I refresh .. is my view loading "too fast"?

I'm having problems with a photo upload system in Codeigniter.
I'm uploading and resizing a photo during registration in my controller, and once that goes through, I load an "upload successful" view where I want to display the photo again.
The problem is,
I step into a "fail" loop that actually seems to not be failing
and
the first time I load my view, the photo isn't displaying (although it has been uploaded, resized, and the path is in my DB). But if I refresh the page, it does display correctly.
Here is the controller .. check the comments close to the bottom, because the top part is basically just the resizing logic and (although it is kind of ugly right now) it does work
public function do_upload()
{
$config['upload_path'] = './upload_pic/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1200';
$config['max_height'] = '768';
$_maxResizedWidth = '242';
$this->load->library('upload', $config);
if ( $this->upload->do_upload() )
{
$this->data['upload_data'] = $this->upload->data();
$this->data['title'] = "Upload Successful";
switch($this->data['upload_data']['file_type']){
case "image/jpg":
$_file_suffix = ".jpg";
break;
case "image/jpeg":
$_file_suffix = ".jpg";
break;
case "image/png":
$_file_suffix = ".png";
break;
case "image/gif":
$_file_suffix = ".gif";
break;
case "image/pjpeg":
$_file_suffix = ".jpg";
break;
}
$_fileName = $this->data['upload_data']['file_name'];
$_oldUploadPath = $config['upload_path'] . $_fileName;
$_random_key = strtotime(date('Y-m-d H:i:s'));
$_newUploadPath = $config['upload_path'] . 'resize_' . $_random_key . $_file_suffix;
rename( $_oldUploadPath, $_newUploadPath );
$_oldSize = getimagesize($_newUploadPath);
$_oldWidth = $_oldSize[0];
if($_oldWidth > $_maxResizedWidth){
$_scale = $_maxResizedWidth/$_oldWidth;
$_oldHeight = $_oldSize[1];
$_imageType = image_type_to_mime_type($_oldSize[2]);
$_newWidth = $_oldWidth * $_scale;
$_newHeight = $_oldHeight * $_scale;
$_resizedImage = imagecreatetruecolor($_newWidth, $_newHeight);
switch($_imageType) {
case "image/gif":
$_source=imagecreatefromgif($_newUploadPath);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$_source=imagecreatefromjpeg($_newUploadPath);
break;
case "image/png":
case "image/x-png":
$_source=imagecreatefrompng($_newUploadPath);
break;
}
imagecopyresampled($_resizedImage, $_source, 0, 0, 0, 0, $_newWidth, $_newHeight, $_oldWidth, $_oldHeight);
switch($_imageType) {
case "image/gif":
imagegif($_resizedImage,$_newUploadPath);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($_resizedImage,$_newUploadPath,90);
break;
case "image/png":
case "image/x-png":
imagepng($_resizedImage,$_newUploadPath);
break;
}
}
$_newUploadPathWithoutDot = substr($_newUploadPath,1);
$this->load->model('Member_model');
$ID = $this->the_user->id;
/// ****************************************************************************
/// I step into this next if loop even though the upload_photo method does work.
/// In my view I get the "there was a problem" .. but the DB has been correctly updated
if(!$this->Member_model->upload_photo( $ID, $_newUploadPathWithoutDot));
{
$uploadData = $this->upload->data();
$this->data['message'] = "There was a problem entering your photo in the database ==";
};
/// And this is the view that's called
$this->load->view('upload_big_success_view', $this->data);
}
else
{
$this->data['message'] = "there was a problem " . $this->upload->display_errors() . dirname(__FILE__);
$this->data['title'] = "Upload Unsuccessful";
$this->load->view('profile_photo_view', $this->data);
}
}
(I know there is a lot of messy in there, and I'll give it a refactor).
It almost seems like the image is "not ready" when the view first loads, even though everything has worked - the upload, the resize, the filepath is entered in the DB... nothing has thrown any errors until it gets to that last loop and it seems to think "->upload_photo()" has failed when it hasn't. And then when I call the view the first time my ..
<img src"<?php echo $the_user->large_image_location; ?>" >
.. produces no output. But after a simple refresh, it does. Although the "there was a problem message" is still displaying in the view.
BTW - here is the model. Nothing fancy.
public function upload_photo($ID, $_newUploadPath)
{
$sql = "UPDATE users SET large_image_location=? WHERE id=?";
$query = $this->db->query($sql, array($_newUploadPath, $ID));
return $query;
}
So any ideas?
Codeigniter won't refresh the page when loading a view, so it will never load the images, instead you will need to tell Codeigniter to refresh the page by using the redirect() function. Instead of loading the success view at the end of the do_upload() method, you should do a redirect to your success page.
I would create a upload_big_success() method, to load your upload_big_success_view for you, then redirect to that method.
Replace the following line in your do_upload() :
$this->load->view('upload_big_success_view', $this->data);
with:
redirect(upload_big_success, 'location');
Then create a method for your success page in the same controller.
public function upload_big_success() {
// And this is the view that's called
$this->load->view('upload_big_success_view');
}

API key for multiple domain script, google map V2

could any one check why my script below is not working please?
<script src="http://maps.google.com/maps?file=api&v=2.x&key=
<?php
$this->googleMapsApiKey = $this->getValueFromDB("google", "googleMapsApiKey");
if ($_SERVER['HTTP_HOST']=='www.ABC.info') {
$this->googleMapsApiKey = "Googlemap-keys";
} elseif ($_SERVER['HTTP_HOST']=='www.CBA.com') {
$this->googleMapsApiKey = "Googlemap-keys";
}
?>" type="text/javascript"></script>
Thanks a lot!!
You can avoid this whole problem: Maps API keys now support multiple domains (and you can edit authorised domains at any time). See Obtaining an API key for more details.
I totally agree with Wrikken, it does not seem that you echoed the variable during the process. Maybe this approach would help:
<?php
print '<script src="http://maps.google.com/maps?file=api&v=2.x&key=';
$this->googleMapsApiKey = $this->getValueFromDB("google", "googleMapsApiKey");
switch ($_SERVER['HTTP_HOST'])
{
//Specific for a domain, but I think that the default handles it against your DB automatically
//case 'www.ABC.info' : $this->googleMapsApiKey = "Googlemap-keys";
// break;
//Same here
// case 'www.CBA.com': $this->googleMapsApiKey = "Googlemap-keys";
// break;
default: $this->googleMapsApiKey = "Googlemap-keys";
}
echo "$this->googleMapsApiKey type=\"text/javascript\"></script>";
?>

Categories