Use Global Variables to dynamically change URL

☆樱花仙子☆ 提交于 2019-12-12 05:15:46

问题


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


回答1:


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).



来源:https://stackoverflow.com/questions/39984235/use-global-variables-to-dynamically-change-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!