使用全局变量来动态更改URL [英] Use Global Variables to dynamically change URL

查看:254
本文介绍了使用全局变量来动态更改URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这将很难解释,

我有一个A文件夹,并且有一个B文件夹。我正在为他们使用一个共同的数据库。

这两个文件夹都有以下文件,其中包含以下文件=> config.php,index.php,upload.php,control_admin.php,admin.php和view.php 。有一些基本的数据库,CSS和JS文件,其中B与A共享(没有任何问题)。



现在A是项目A,B是项目B.

对于每个项目,我都有URL => a.example.com& b.example.com



在a.example.com/index.php上传一个像project_name = Apple Version = 1这样的图像文件。



在b.example.com/index.php上传一个像project_name = Banana Version = 1这样的特征的图像文件。

这些图像分别上传到A和B中的图像文件夹。



现在查看这些图片,我可以到

a.example.com \view。 php?$ version = 1,可以看到图片。



同样适用于b.example.com



我在.htaccess中修改了这个内容,以创建一个友好的URL,它将我带到


$ b $ .example.com \1,并根据需要显示图像。



现在出现这个问题。每个view.php文件都有以下图片链接:

 < img src =<?php echohttp: //\".$GLOBALS['url'].\"\".$GLOBALS['img_folder'].\"/\".\"new?> style ='margin:0px auto;显示:块;最大宽度:100%;高度:自动;'> 

我从每个文件的config.php取这些全局变量。



对于A:

 <?php $ GLOBALS ['project_name'] ='Apple'; ?> 

<?php $ GLOBALS ['url'] ='a.example.com/'?>

<?php $ GLOBALS [folder] ='FolderA'; ?>

<?php $ GLOBALS ['img_folder'] ='AppleImages'; ?>

对于B:

 <?php $ GLOBALS ['project_name'] ='香蕉';?> 

<?php $ GLOBALS ['url'] ='b.example.com/'?>

<?php $ GLOBALS [folder] ='FolderB'; ?>

<?php $ GLOBALS ['img_folder'] ='BananaImages'; ?>

现在的问题是,如果我上传A的版本1,然后上传B的版本1,请转到a.example.com/1或b.example.com/1的友好网址链接...我在B上传文件后无法看到A处的网址,因为该网址很难指向B因为这是最近上传到同一个数据库。



如果我上传到a.example.com,然后上传到b .example.com,具有相同版本的文件...我可以在各自的URL上看到这两个图像



a.example.com/2和b.example.com/ 2



我希望我有道理。提前致谢。



https://drive.google.com/drive/folders/0B5nDbj-RhZJMa3drNFlfRzVaLXc?usp=sharing

解决方案

<



view.php:line 64

  $ project_name_download_form = $ _GET ['project_name']; 

除非您使用像这样的网址访问view.php:

  a.example.com \view.php?version = 1& project_name = apple 

您的 $ project_name_download_form 将有一个空字符串值,并且您的SQL查询变为:

  SELECT demo_id,demo_name,demo_version,demo_details,file 
FROM demo
WHERE demo_name =''
AND demo_version ='1'

所以2行动,将第64行改为:

  $ project_name_download_form = $ GLOBALS ['project_name']; 

然后直接检查数据库以确保demo_name列的值已被设置只是空白)。


So this is going to be really hard to explain,

I have an A folder and I have a B folder. I am using a common database for both of them.

Both folder have following files, inside each of them => config.php, index.php, upload.php, control_admin.php, admin.php and view.php. There are some basic database, CSS and JS files which B shares with A(not of any problem).

Now A is for project A and B is for project B.

for each of the projects, I have URLs => a.example.com & b.example.com

At a.example.com/index.php I upload an image file which characteristics like project_name = Apple Version = 1.

At b.example.com/index.php I upload an image file which characteristics like project_name = Banana Version = 1.

These images are uploaded to image folders in A and B respectively.

Now to view these images, I could have gone to

a.example.com\view.php?$version=1 and could have seen the pic.

similarly for b.example.com

I have modified this in .htaccess to make a friendly URL which takes me to

a.example.com\1 and displays the image as required.

Now comes the problem. Each of the view.php file have the following image link

<img src = "<?php echo     "http://".$GLOBALS['url']."".$GLOBALS['img_folder']."/".$new ?>" style = 'margin: 0px auto; display:block; max-width: 100%;height: auto;'>

I take these global variables from config.php of each file.

For A:

<?php $GLOBALS['project_name'] = 'Apple';?>

<?php $GLOBALS['url'] = 'a.example.com/'?>

<?php $GLOBALS["folder"] = 'FolderA'; ?>

<?php $GLOBALS['img_folder'] = 'AppleImages'; ?> 

For B:

<?php $GLOBALS['project_name'] = 'Banana';?>

<?php $GLOBALS['url'] = 'b.example.com/'?>

<?php $GLOBALS["folder"] = 'FolderB'; ?>

<?php $GLOBALS['img_folder'] = 'BananaImages'; ?> 

Now the issue is, if I upload version 1 of A and then version 1 of B and then I go to the link which is friendly URL from a.example.com/1 or b.example.com/1... I cannot see the one at A after I upload a file at B. Because the URL is hard pointing at B as it is the recent upload in the same database.

What can I do to the URL to make sure, if I upload to a.example.com and then to b.example.com, files with same version... I can see both images at their respective URLs

a.example.com/2 and b.example.com/2

I hope I made sense. Thanks in advance.

https://drive.google.com/drive/folders/0B5nDbj-RhZJMa3drNFlfRzVaLXc?usp=sharing

解决方案

I looked through the google drive link you provided.

view.php : line 64

$project_name_download_form = $_GET['project_name'];

Unless you are accessing view.php with a url like this:

a.example.com\view.php?version=1&project_name=apple

Your $project_name_download_form will have an empty string value and your SQL query becomes:

SELECT demo_id, demo_name, demo_version, demo_details, file 
                      FROM demo
                      WHERE  demo_name = ''
                      AND  demo_version = '1'

So 2 actions, change line 64 to:

$project_name_download_form = $GLOBALS['project_name'];

And then check the database directly to make sure the demo_name column has values being set in it (and not just blank).

这篇关于使用全局变量来动态更改URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆